
<!-- saved from url=(0048)https://opensource.afterturn.cn/doc/easypoi.html -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        
        <title>风铃开源文档</title>
        <link rel="stylesheet" type="text/css" href="./easypoi_files/github2-rightpart.css" media="all">
        <link rel="stylesheet" type="text/css" href="./easypoi_files/github1-contents.css">
        <link rel="stylesheet" href="./easypoi_files/zTreeStyle.css" type="text/css">

        <style>
            .ztree li a.curSelectedNode {
                padding-top: 0px;
                background-color: #FFE6B0;
                color: black;
                height: 16px;
                border: 1px #FFB951 solid;
                opacity: 0.8;
            }
            .ztree{
                overflow: auto;
                height:100%;
                min-height: 200px;
                top: 0px;
            }
			.footer p {
			  color: #7f8c8d;
			  margin: 0;
			  padding: 15px 15px;
			  text-align: center;
			  background: #2d3e50;
			}
        </style>
    </head>
    <body style="">
        <div>
            <div style="width:30%;">
                <ul id="tree" class="ztree" style="width: 260px; overflow: auto; position: fixed; z-index: 2147483647; border: 0px none; left: 0px; bottom: 0px;"><li id="tree_1" class="level0" tabindex="0" hidefocus="true" treenode=""><span id="tree_1_switch" title="" class="button level0 switch roots_docu" treenode_switch=""></span><a id="tree_1_a" class="level0 curSelectedNode" treenode_a="" onclick="" target="_blank" style="" title="风铃文档"><span id="tree_1_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_1_span">风铃文档</span></a></li><li id="tree_2" class="level0" tabindex="0" hidefocus="true" treenode=""><span id="tree_2_switch" title="" class="button level0 switch center_open" treenode_switch=""></span><a id="tree_2_a" class="level0" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#1" target="_self" style="" title="1. 前言"><span id="tree_2_ico" title="" treenode_ico="" class="button ico_open" style="width:0px;height:0px;"></span><span id="tree_2_span">1. 前言</span></a><ul id="tree_2_ul" class="level0 line" style="display:block"><li id="tree_3" class="level1" tabindex="0" hidefocus="true" treenode=""><span id="tree_3_switch" title="" class="button level1 switch center_docu" treenode_switch=""></span><a id="tree_3_a" class="level1" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#101" target="_self" style="" title="1.1 前言"><span id="tree_3_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_3_span">1.1 前言</span></a></li><li id="tree_4" class="level1" tabindex="0" hidefocus="true" treenode=""><span id="tree_4_switch" title="" class="button level1 switch center_docu" treenode_switch=""></span><a id="tree_4_a" class="level1" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#102" target="_self" style="" title="1.2 Easypoi介绍"><span id="tree_4_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_4_span">1.2 Easypoi介绍</span></a></li><li id="tree_5" class="level1" tabindex="0" hidefocus="true" treenode=""><span id="tree_5_switch" title="" class="button level1 switch center_docu" treenode_switch=""></span><a id="tree_5_a" class="level1" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#103" target="_self" style="" title="1.3 使用"><span id="tree_5_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_5_span">1.3 使用</span></a></li><li id="tree_6" class="level1" tabindex="0" hidefocus="true" treenode=""><span id="tree_6_switch" title="" class="button level1 switch center_docu" treenode_switch=""></span><a id="tree_6_a" class="level1" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#104" target="_self" style="" title="1.4 测试项目"><span id="tree_6_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_6_span">1.4 测试项目</span></a></li><li id="tree_7" class="level1" tabindex="0" hidefocus="true" treenode=""><span id="tree_7_switch" title="" class="button level1 switch center_docu" treenode_switch=""></span><a id="tree_7_a" class="level1" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#105" target="_self" style="" title="1.5 可能存在的小坑"><span id="tree_7_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_7_span">1.5 可能存在的小坑</span></a></li><li id="tree_8" class="level1" tabindex="0" hidefocus="true" treenode=""><span id="tree_8_switch" title="" class="button level1 switch bottom_open" treenode_switch=""></span><a id="tree_8_a" class="level1" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#106" target="_self" style="" title="1.6 我认为的最佳实践 ,什么情况该用那个方法"><span id="tree_8_ico" title="" treenode_ico="" class="button ico_open" style="width:0px;height:0px;"></span><span id="tree_8_span">1.6 我认为的最佳实践 ,什么情况该用那个方法</span></a><ul id="tree_8_ul" class="level1 " style="display:block"><li id="tree_9" class="level2" tabindex="0" hidefocus="true" treenode=""><span id="tree_9_switch" title="" class="button level2 switch center_docu" treenode_switch=""></span><a id="tree_9_a" class="level2" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#10601" target="_self" style="" title="1.6.1 量不大,表简单的读写"><span id="tree_9_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_9_span">1.6.1 量不大,表简单的读写</span></a></li><li id="tree_10" class="level2" tabindex="0" hidefocus="true" treenode=""><span id="tree_10_switch" title="" class="button level2 switch center_docu" treenode_switch=""></span><a id="tree_10_a" class="level2" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#10602" target="_self" style="" title="1.6.2 对象不固定的导入导出"><span id="tree_10_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_10_span">1.6.2 对象不固定的导入导出</span></a></li><li id="tree_11" class="level2" tabindex="0" hidefocus="true" treenode=""><span id="tree_11_switch" title="" class="button level2 switch center_docu" treenode_switch=""></span><a id="tree_11_a" class="level2" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#10603" target="_self" style="" title="1.6.3 量稍微有点大10W内"><span id="tree_11_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_11_span">1.6.3 量稍微有点大10W内</span></a></li><li id="tree_12" class="level2" tabindex="0" hidefocus="true" treenode=""><span id="tree_12_switch" title="" class="button level2 switch center_docu" treenode_switch=""></span><a id="tree_12_a" class="level2" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#10604" target="_self" style="" title="1.6.4 更大量的读取,或者需要校验等时间稍长,或者频繁导入容易内存溢出"><span id="tree_12_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_12_span">1.6.4 更大量的读取,或者需要校验等时间稍长,或者频繁导入容易内存溢出</span></a></li><li id="tree_13" class="level2" tabindex="0" hidefocus="true" treenode=""><span id="tree_13_switch" title="" class="button level2 switch center_docu" treenode_switch=""></span><a id="tree_13_a" class="level2" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#10605" target="_self" style="" title="1.6.5 更加大量的数据,百万级以上"><span id="tree_13_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_13_span">1.6.5 更加大量的数据,百万级以上</span></a></li><li id="tree_14" class="level2" tabindex="0" hidefocus="true" treenode=""><span id="tree_14_switch" title="" class="button level2 switch bottom_docu" treenode_switch=""></span><a id="tree_14_a" class="level2" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#10606" target="_self" style="" title="1.6.6 模板适合在什么环境"><span id="tree_14_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_14_span">1.6.6 模板适合在什么环境</span></a></li></ul></li></ul></li><li id="tree_15" class="level0" tabindex="0" hidefocus="true" treenode=""><span id="tree_15_switch" title="" class="button level0 switch center_open" treenode_switch=""></span><a id="tree_15_a" class="level0" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#2" target="_self" style="" title="2.Excel注解版"><span id="tree_15_ico" title="" treenode_ico="" class="button ico_open" style="width:0px;height:0px;"></span><span id="tree_15_span">2.Excel注解版</span></a><ul id="tree_15_ul" class="level0 line" style="display:block"><li id="tree_16" class="level1" tabindex="0" hidefocus="true" treenode=""><span id="tree_16_switch" title="" class="button level1 switch center_docu" treenode_switch=""></span><a id="tree_16_a" class="level1" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#201" target="_self" style="" title="2.1 Excel导入导出"><span id="tree_16_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_16_span">2.1 Excel导入导出</span></a></li><li id="tree_17" class="level1" tabindex="0" hidefocus="true" treenode=""><span id="tree_17_switch" title="" class="button level1 switch bottom_open" treenode_switch=""></span><a id="tree_17_a" class="level1" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#202" target="_self" style="" title="2.2 注解"><span id="tree_17_ico" title="" treenode_ico="" class="button ico_open" style="width:0px;height:0px;"></span><span id="tree_17_span">2.2 注解</span></a><ul id="tree_17_ul" class="level1 " style="display:block"><li id="tree_18" class="level2" tabindex="0" hidefocus="true" treenode=""><span id="tree_18_switch" title="" class="button level2 switch center_docu" treenode_switch=""></span><a id="tree_18_a" class="level2" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#40201" target="_self" style="" title="注解介绍"><span id="tree_18_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_18_span">注解介绍</span></a></li><li id="tree_19" class="level2" tabindex="0" hidefocus="true" treenode=""><span id="tree_19_switch" title="" class="button level2 switch center_docu" treenode_switch=""></span><a id="tree_19_a" class="level2" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#40202" target="_self" style="" title="@Excel"><span id="tree_19_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_19_span">@Excel</span></a></li><li id="tree_20" class="level2" tabindex="0" hidefocus="true" treenode=""><span id="tree_20_switch" title="" class="button level2 switch center_docu" treenode_switch=""></span><a id="tree_20_a" class="level2" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#40203" target="_self" style="" title="@ExcelCollection"><span id="tree_20_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_20_span">@ExcelCollection</span></a></li><li id="tree_21" class="level2" tabindex="0" hidefocus="true" treenode=""><span id="tree_21_switch" title="" class="button level2 switch center_docu" treenode_switch=""></span><a id="tree_21_a" class="level2" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#40204" target="_self" style="" title="@ExcelEntity"><span id="tree_21_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_21_span">@ExcelEntity</span></a></li><li id="tree_22" class="level2" tabindex="0" hidefocus="true" treenode=""><span id="tree_22_switch" title="" class="button level2 switch center_docu" treenode_switch=""></span><a id="tree_22_a" class="level2" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#40205" target="_self" style="" title="@ExcelIgnore"><span id="tree_22_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_22_span">@ExcelIgnore</span></a></li><li id="tree_23" class="level2" tabindex="0" hidefocus="true" treenode=""><span id="tree_23_switch" title="" class="button level2 switch bottom_docu" treenode_switch=""></span><a id="tree_23_a" class="level2" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#40206" target="_self" style="" title="@ExcelTarget"><span id="tree_23_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_23_span">@ExcelTarget</span></a></li></ul></li></ul></li><li id="tree_24" class="level0" tabindex="0" hidefocus="true" treenode=""><span id="tree_24_switch" title="" class="button level0 switch center_open" treenode_switch=""></span><a id="tree_24_a" class="level0" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#3" target="_self" style="" title="2.3 注解导出,导入"><span id="tree_24_ico" title="" treenode_ico="" class="button ico_open" style="width:0px;height:0px;"></span><span id="tree_24_span">2.3 注解导出,导入</span></a><ul id="tree_24_ul" class="level0 line" style="display:block"><li id="tree_25" class="level1" tabindex="0" hidefocus="true" treenode=""><span id="tree_25_switch" title="" class="button level1 switch center_open" treenode_switch=""></span><a id="tree_25_a" class="level1" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#301" target="_self" style="" title="2.3.1 对象定义"><span id="tree_25_ico" title="" treenode_ico="" class="button ico_open" style="width:0px;height:0px;"></span><span id="tree_25_span">2.3.1 对象定义</span></a><ul id="tree_25_ul" class="level1 line" style="display:block"><li id="tree_26" class="level2" tabindex="0" hidefocus="true" treenode=""><span id="tree_26_switch" title="" class="button level2 switch center_docu" treenode_switch=""></span><a id="tree_26_a" class="level2" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#90101" target="_self" style="" title="2.3.2 集合定义"><span id="tree_26_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_26_span">2.3.2 集合定义</span></a></li><li id="tree_27" class="level2" tabindex="0" hidefocus="true" treenode=""><span id="tree_27_switch" title="" class="button level2 switch center_docu" treenode_switch=""></span><a id="tree_27_a" class="level2" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#90102" target="_self" style="" title="2.3.3 图片的导出"><span id="tree_27_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_27_span">2.3.3 图片的导出</span></a></li><li id="tree_28" class="level2" tabindex="0" hidefocus="true" treenode=""><span id="tree_28_switch" title="" class="button level2 switch center_docu" treenode_switch=""></span><a id="tree_28_a" class="level2" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#90103" target="_self" style="" title="2.3.4 Excel导入介绍"><span id="tree_28_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_28_span">2.3.4 Excel导入介绍</span></a></li><li id="tree_29" class="level2" tabindex="0" hidefocus="true" treenode=""><span id="tree_29_switch" title="" class="button level2 switch center_docu" treenode_switch=""></span><a id="tree_29_a" class="level2" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#90104" target="_self" style="" title="2.3.5 Excel导入小功能"><span id="tree_29_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_29_span">2.3.5 Excel导入小功能</span></a></li><li id="tree_30" class="level2" tabindex="0" hidefocus="true" treenode=""><span id="tree_30_switch" title="" class="button level2 switch center_docu" treenode_switch=""></span><a id="tree_30_a" class="level2" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#90105" target="_self" style="" title="2.3.6 图片的导入"><span id="tree_30_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_30_span">2.3.6 图片的导入</span></a></li><li id="tree_31" class="level2" tabindex="0" hidefocus="true" treenode=""><span id="tree_31_switch" title="" class="button level2 switch bottom_docu" treenode_switch=""></span><a id="tree_31_a" class="level2" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#90106" target="_self" style="" title="2.3.7 Excel多Sheet导出"><span id="tree_31_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_31_span">2.3.7 Excel多Sheet导出</span></a></li></ul></li><li id="tree_32" class="level1" tabindex="0" hidefocus="true" treenode=""><span id="tree_32_switch" title="" class="button level1 switch center_docu" treenode_switch=""></span><a id="tree_32_a" class="level1" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#302" target="_self" style="" title="2.4 注解变种-更自由的导出"><span id="tree_32_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_32_span">2.4 注解变种-更自由的导出</span></a></li><li id="tree_33" class="level1" tabindex="0" hidefocus="true" treenode=""><span id="tree_33_switch" title="" class="button level1 switch center_docu" treenode_switch=""></span><a id="tree_33_a" class="level1" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#303" target="_self" style="" title="2.5 Map导入,自由发挥"><span id="tree_33_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_33_span">2.5 Map导入,自由发挥</span></a></li><li id="tree_34" class="level1" tabindex="0" hidefocus="true" treenode=""><span id="tree_34_switch" title="" class="button level1 switch center_docu" treenode_switch=""></span><a id="tree_34_a" class="level1" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#304" target="_self" style="" title="2.6 Excel的样式自定义"><span id="tree_34_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_34_span">2.6 Excel的样式自定义</span></a></li><li id="tree_35" class="level1" tabindex="0" hidefocus="true" treenode=""><span id="tree_35_switch" title="" class="button level1 switch center_docu" treenode_switch=""></span><a id="tree_35_a" class="level1" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#305" target="_self" style="" title="2.7 如何自定义数据处理"><span id="tree_35_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_35_span">2.7 如何自定义数据处理</span></a></li><li id="tree_36" class="level1" tabindex="0" hidefocus="true" treenode=""><span id="tree_36_switch" title="" class="button level1 switch center_docu" treenode_switch=""></span><a id="tree_36_a" class="level1" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#306" target="_self" style="" title="2.8 Excel导入校验"><span id="tree_36_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_36_span">2.8 Excel导入校验</span></a></li><li id="tree_37" class="level1" tabindex="0" hidefocus="true" treenode=""><span id="tree_37_switch" title="" class="button level1 switch center_docu" treenode_switch=""></span><a id="tree_37_a" class="level1" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#307" target="_self" style="" title="使用"><span id="tree_37_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_37_span">使用</span></a></li><li id="tree_38" class="level1" tabindex="0" hidefocus="true" treenode=""><span id="tree_38_switch" title="" class="button level1 switch center_open" treenode_switch=""></span><a id="tree_38_a" class="level1" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#308" target="_self" style="" title="2.9 Excel 大数据读取"><span id="tree_38_ico" title="" treenode_ico="" class="button ico_open" style="width:0px;height:0px;"></span><span id="tree_38_span">2.9 Excel 大数据读取</span></a><ul id="tree_38_ul" class="level1 line" style="display:block"><li id="tree_39" class="level2" tabindex="0" hidefocus="true" treenode=""><span id="tree_39_switch" title="" class="button level2 switch center_docu" treenode_switch=""></span><a id="tree_39_a" class="level2" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#90801" target="_self" style="" title="2.9.1 ExceL by sax读取"><span id="tree_39_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_39_span">2.9.1 ExceL by sax读取</span></a></li><li id="tree_40" class="level2" tabindex="0" hidefocus="true" treenode=""><span id="tree_40_switch" title="" class="button level2 switch bottom_docu" treenode_switch=""></span><a id="tree_40_a" class="level2" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#90802" target="_self" style="" title="2.9.2 CSV导入"><span id="tree_40_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_40_span">2.9.2 CSV导入</span></a></li></ul></li><li id="tree_41" class="level1" tabindex="0" hidefocus="true" treenode=""><span id="tree_41_switch" title="" class="button level1 switch center_docu" treenode_switch=""></span><a id="tree_41_a" class="level1" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#309" target="_self" style="" title="2.10 Excel大数据导出"><span id="tree_41_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_41_span">2.10 Excel大数据导出</span></a></li><li id="tree_42" class="level1" tabindex="0" hidefocus="true" treenode=""><span id="tree_42_switch" title="" class="button level1 switch center_docu" treenode_switch=""></span><a id="tree_42_a" class="level1" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#310" target="_self" style="" title="2.11 导入获取Key-Value"><span id="tree_42_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_42_span">2.11 导入获取Key-Value</span></a></li><li id="tree_43" class="level1" tabindex="0" hidefocus="true" treenode=""><span id="tree_43_switch" title="" class="button level1 switch center_docu" treenode_switch=""></span><a id="tree_43_a" class="level1" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#311" target="_self" style="" title="2.12 groupname和ExcelEntity的name属性"><span id="tree_43_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_43_span">2.12 groupname和ExcelEntity的name属性</span></a></li><li id="tree_44" class="level1" tabindex="0" hidefocus="true" treenode=""><span id="tree_44_switch" title="" class="button level1 switch bottom_docu" treenode_switch=""></span><a id="tree_44_a" class="level1" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#312" target="_self" style="" title="2.13 多线程导入基于ForkJoin @Since4.1"><span id="tree_44_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_44_span">2.13 多线程导入基于ForkJoin @Since4.1</span></a></li></ul></li><li id="tree_45" class="level0" tabindex="0" hidefocus="true" treenode=""><span id="tree_45_switch" title="" class="button level0 switch center_open" treenode_switch=""></span><a id="tree_45_a" class="level0" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#4" target="_self" style="" title="3. Excel模板处理"><span id="tree_45_ico" title="" treenode_ico="" class="button ico_open" style="width:0px;height:0px;"></span><span id="tree_45_span">3. Excel模板处理</span></a><ul id="tree_45_ul" class="level0 line" style="display:block"><li id="tree_46" class="level1" tabindex="0" hidefocus="true" treenode=""><span id="tree_46_switch" title="" class="button level1 switch center_docu" treenode_switch=""></span><a id="tree_46_a" class="level1" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#401" target="_self" style="" title="3.1 模板 指令介绍"><span id="tree_46_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_46_span">3.1 模板 指令介绍</span></a></li><li id="tree_47" class="level1" tabindex="0" hidefocus="true" treenode=""><span id="tree_47_switch" title="" class="button level1 switch center_docu" treenode_switch=""></span><a id="tree_47_a" class="level1" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#402" target="_self" style="" title="测试项目"><span id="tree_47_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_47_span">测试项目</span></a></li><li id="tree_48" class="level1" tabindex="0" hidefocus="true" treenode=""><span id="tree_48_switch" title="" class="button level1 switch center_docu" treenode_switch=""></span><a id="tree_48_a" class="level1" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#403" target="_self" style="" title="3.2 基本导出"><span id="tree_48_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_48_span">3.2 基本导出</span></a></li><li id="tree_49" class="level1" tabindex="0" hidefocus="true" treenode=""><span id="tree_49_switch" title="" class="button level1 switch center_docu" treenode_switch=""></span><a id="tree_49_a" class="level1" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#404" target="_self" style="" title="3.3 模板当中使用注解"><span id="tree_49_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_49_span">3.3 模板当中使用注解</span></a></li><li id="tree_50" class="level1" tabindex="0" hidefocus="true" treenode=""><span id="tree_50_switch" title="" class="button level1 switch center_docu" treenode_switch=""></span><a id="tree_50_a" class="level1" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#405" target="_self" style="" title="3.4 图片导出"><span id="tree_50_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_50_span">3.4 图片导出</span></a></li><li id="tree_51" class="level1" tabindex="0" hidefocus="true" treenode=""><span id="tree_51_switch" title="" class="button level1 switch center_docu" treenode_switch=""></span><a id="tree_51_a" class="level1" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#406" target="_self" style="" title="3.5 clone sheet导出多个模板一致的表格 @Since 4.1"><span id="tree_51_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_51_span">3.5 clone sheet导出多个模板一致的表格 @Since 4.1</span></a></li><li id="tree_52" class="level1" tabindex="0" hidefocus="true" treenode=""><span id="tree_52_switch" title="" class="button level1 switch bottom_docu" treenode_switch=""></span><a id="tree_52_a" class="level1" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#407" target="_self" style="" title="3.6 模板支持多层循环 @Since 4.1.1"><span id="tree_52_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_52_span">3.6 模板支持多层循环 @Since 4.1.1</span></a></li></ul></li><li id="tree_53" class="level0" tabindex="0" hidefocus="true" treenode=""><span id="tree_53_switch" title="" class="button level0 switch center_open" treenode_switch=""></span><a id="tree_53_a" class="level0" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#5" target="_self" style="" title="4.Excel&amp;Html互转"><span id="tree_53_ico" title="" treenode_ico="" class="button ico_open" style="width:0px;height:0px;"></span><span id="tree_53_span">4.Excel&amp;Html互转</span></a><ul id="tree_53_ul" class="level0 line" style="display:block"><li id="tree_54" class="level1" tabindex="0" hidefocus="true" treenode=""><span id="tree_54_switch" title="" class="button level1 switch center_docu" treenode_switch=""></span><a id="tree_54_a" class="level1" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#501" target="_self" style="" title="4.1 Excel 的Html预览"><span id="tree_54_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_54_span">4.1 Excel 的Html预览</span></a></li><li id="tree_55" class="level1" tabindex="0" hidefocus="true" treenode=""><span id="tree_55_switch" title="" class="button level1 switch bottom_docu" treenode_switch=""></span><a id="tree_55_a" class="level1" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#502" target="_self" style="" title="4.2 html转Excel更神奇的导出"><span id="tree_55_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_55_span">4.2 html转Excel更神奇的导出</span></a></li></ul></li><li id="tree_56" class="level0" tabindex="0" hidefocus="true" treenode=""><span id="tree_56_switch" title="" class="button level0 switch center_open" treenode_switch=""></span><a id="tree_56_a" class="level0" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#6" target="_self" style="" title="5.word模板处理"><span id="tree_56_ico" title="" treenode_ico="" class="button ico_open" style="width:0px;height:0px;"></span><span id="tree_56_span">5.word模板处理</span></a><ul id="tree_56_ul" class="level0 line" style="display:block"><li id="tree_57" class="level1" tabindex="0" hidefocus="true" treenode=""><span id="tree_57_switch" title="" class="button level1 switch center_docu" treenode_switch=""></span><a id="tree_57_a" class="level1" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#601" target="_self" style="" title="5.1 word模板导出"><span id="tree_57_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_57_span">5.1 word模板导出</span></a></li><li id="tree_58" class="level1" tabindex="0" hidefocus="true" treenode=""><span id="tree_58_switch" title="" class="button level1 switch bottom_docu" treenode_switch=""></span><a id="tree_58_a" class="level1" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#602" target="_self" style="" title="5.2 单模板生成多页数据"><span id="tree_58_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_58_span">5.2 单模板生成多页数据</span></a></li></ul></li><li id="tree_59" class="level0" tabindex="0" hidefocus="true" treenode=""><span id="tree_59_switch" title="" class="button level0 switch center_docu" treenode_switch=""></span><a id="tree_59_a" class="level0" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#7" target="_self" style="" title="6.PDF处理"><span id="tree_59_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_59_span">6.PDF处理</span></a></li><li id="tree_60" class="level0" tabindex="0" hidefocus="true" treenode=""><span id="tree_60_switch" title="" class="button level0 switch center_open" treenode_switch=""></span><a id="tree_60_a" class="level0" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#8" target="_self" style="" title="7. CSV处理"><span id="tree_60_ico" title="" treenode_ico="" class="button ico_open" style="width:0px;height:0px;"></span><span id="tree_60_span">7. CSV处理</span></a><ul id="tree_60_ul" class="level0 line" style="display:block"><li id="tree_61" class="level1" tabindex="0" hidefocus="true" treenode=""><span id="tree_61_switch" title="" class="button level1 switch center_docu" treenode_switch=""></span><a id="tree_61_a" class="level1" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#801" target="_self" style="" title="7.1 CSV导入处理"><span id="tree_61_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_61_span">7.1 CSV导入处理</span></a></li><li id="tree_62" class="level1" tabindex="0" hidefocus="true" treenode=""><span id="tree_62_switch" title="" class="button level1 switch bottom_docu" treenode_switch=""></span><a id="tree_62_a" class="level1" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#802" target="_self" style="" title="7.2 CSV导出"><span id="tree_62_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_62_span">7.2 CSV导出</span></a></li></ul></li><li id="tree_63" class="level0" tabindex="0" hidefocus="true" treenode=""><span id="tree_63_switch" title="" class="button level0 switch center_docu" treenode_switch=""></span><a id="tree_63_a" class="level0" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#9" target="_self" style="" title="8.Spring MVC"><span id="tree_63_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_63_span">8.Spring MVC</span></a></li><li id="tree_64" class="level0" tabindex="0" hidefocus="true" treenode=""><span id="tree_64_switch" title="" class="button level0 switch center_open" treenode_switch=""></span><a id="tree_64_a" class="level0" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#10" target="_self" style="" title="8.1 View 介绍"><span id="tree_64_ico" title="" treenode_ico="" class="button ico_open" style="width:0px;height:0px;"></span><span id="tree_64_span">8.1 View 介绍</span></a><ul id="tree_64_ul" class="level0 line" style="display:block"><li id="tree_65" class="level1" tabindex="0" hidefocus="true" treenode=""><span id="tree_65_switch" title="" class="button level1 switch center_docu" treenode_switch=""></span><a id="tree_65_a" class="level1" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#1001" target="_self" style="" title="8.2  大数据导出View的用法"><span id="tree_65_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_65_span">8.2  大数据导出View的用法</span></a></li><li id="tree_66" class="level1" tabindex="0" hidefocus="true" treenode=""><span id="tree_66_switch" title="" class="button level1 switch center_docu" treenode_switch=""></span><a id="tree_66_a" class="level1" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#1002" target="_self" style="" title="8.3 注解导出View用法"><span id="tree_66_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_66_span">8.3 注解导出View用法</span></a></li><li id="tree_67" class="level1" tabindex="0" hidefocus="true" treenode=""><span id="tree_67_switch" title="" class="button level1 switch center_docu" treenode_switch=""></span><a id="tree_67_a" class="level1" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#1003" target="_self" style="" title="8.4 注解变种Map类型的导出View"><span id="tree_67_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_67_span">8.4 注解变种Map类型的导出View</span></a></li><li id="tree_68" class="level1" tabindex="0" hidefocus="true" treenode=""><span id="tree_68_switch" title="" class="button level1 switch center_docu" treenode_switch=""></span><a id="tree_68_a" class="level1" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#1004" target="_self" style="" title="8.5Excel模板导出View"><span id="tree_68_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_68_span">8.5Excel模板导出View</span></a></li><li id="tree_69" class="level1" tabindex="0" hidefocus="true" treenode=""><span id="tree_69_switch" title="" class="button level1 switch bottom_docu" treenode_switch=""></span><a id="tree_69_a" class="level1" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#1005" target="_self" style="" title="8.6 PoiBaseView.render view的补救"><span id="tree_69_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_69_span">8.6 PoiBaseView.render view的补救</span></a></li></ul></li><li id="tree_70" class="level0" tabindex="0" hidefocus="true" treenode=""><span id="tree_70_switch" title="" class="button level0 switch center_docu" treenode_switch=""></span><a id="tree_70_a" class="level0" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#11" target="_self" style="" title="9.spring boot"><span id="tree_70_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_70_span">9.spring boot</span></a></li><li id="tree_71" class="level0" tabindex="0" hidefocus="true" treenode=""><span id="tree_71_switch" title="" class="button level0 switch center_docu" treenode_switch=""></span><a id="tree_71_a" class="level0" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#12" target="_self" style="" title="9.1 spring boot start"><span id="tree_71_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_71_span">9.1 spring boot start</span></a></li><li id="tree_72" class="level0" tabindex="0" hidefocus="true" treenode=""><span id="tree_72_switch" title="" class="button level0 switch bottom_open" treenode_switch=""></span><a id="tree_72_a" class="level0" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#13" target="_self" style="" title="10.常见问题解答"><span id="tree_72_ico" title="" treenode_ico="" class="button ico_open" style="width:0px;height:0px;"></span><span id="tree_72_span">10.常见问题解答</span></a><ul id="tree_72_ul" class="level0 " style="display:block"><li id="tree_73" class="level1" tabindex="0" hidefocus="true" treenode=""><span id="tree_73_switch" title="" class="button level1 switch bottom_open" treenode_switch=""></span><a id="tree_73_a" class="level1" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#1301" target="_self" style="" title="10.1 导入时为啥这行为空还读取 或者为啥只有3行却读取了100行数据"><span id="tree_73_ico" title="" treenode_ico="" class="button ico_open" style="width:0px;height:0px;"></span><span id="tree_73_span">10.1 导入时为啥这行为空还读取 或者为啥只有3行却读取了100行数据</span></a><ul id="tree_73_ul" class="level1 " style="display:block"><li id="tree_74" class="level2" tabindex="0" hidefocus="true" treenode=""><span id="tree_74_switch" title="" class="button level2 switch center_docu" treenode_switch=""></span><a id="tree_74_a" class="level2" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#1690101" target="_self" style="" title="10.2 模板如何合并单元格"><span id="tree_74_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_74_span">10.2 模板如何合并单元格</span></a></li><li id="tree_75" class="level2" tabindex="0" hidefocus="true" treenode=""><span id="tree_75_switch" title="" class="button level2 switch center_docu" treenode_switch=""></span><a id="tree_75_a" class="level2" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#1690102" target="_self" style="" title="10.3 如何让单元格是数组"><span id="tree_75_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_75_span">10.3 如何让单元格是数组</span></a></li><li id="tree_76" class="level2" tabindex="0" hidefocus="true" treenode=""><span id="tree_76_switch" title="" class="button level2 switch center_docu" treenode_switch=""></span><a id="tree_76_a" class="level2" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#1690103" target="_self" style="" title="10.4 类找不到怎么办"><span id="tree_76_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_76_span">10.4 类找不到怎么办</span></a></li><li id="tree_77" class="level2" tabindex="0" hidefocus="true" treenode=""><span id="tree_77_switch" title="" class="button level2 switch center_docu" treenode_switch=""></span><a id="tree_77_a" class="level2" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#1690104" target="_self" style="" title="10.5 replace NULL值问题"><span id="tree_77_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_77_span">10.5 replace NULL值问题</span></a></li><li id="tree_78" class="level2" tabindex="0" hidefocus="true" treenode=""><span id="tree_78_switch" title="" class="button level2 switch center_docu" treenode_switch=""></span><a id="tree_78_a" class="level2" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#1690105" target="_self" style="" title="10.6 无表头或者表头重复不好判断如何解决"><span id="tree_78_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_78_span">10.6 无表头或者表头重复不好判断如何解决</span></a></li><li id="tree_79" class="level2" tabindex="0" hidefocus="true" treenode=""><span id="tree_79_switch" title="" class="button level2 switch bottom_docu" treenode_switch=""></span><a id="tree_79_a" class="level2" treenode_a="" onclick="" href="https://opensource.afterturn.cn/doc/easypoi.html#1690106" target="_self" style="" title="10.7 模板导出一对多，如何合并单元格和循环"><span id="tree_79_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="tree_79_span">10.7 模板导出一对多，如何合并单元格和循环</span></a></li></ul></li></ul></li></ul>
            </div>
            <div id="readme" style="width: 70%; margin-left: 25%; height: 63563px;">
                <article class="markdown-body">


  
    <title>no title</title>
    
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
    .markdown-preview{width:100%;height:100%;box-sizing:border-box}.markdown-preview .pagebreak,.markdown-preview .newpage{page-break-before:always}.markdown-preview pre.line-numbers{position:relative;padding-left:3.8em;counter-reset:linenumber}.markdown-preview pre.line-numbers>code{position:relative}.markdown-preview pre.line-numbers .line-numbers-rows{position:absolute;pointer-events:none;top:1em;font-size:100%;left:0;width:3em;letter-spacing:-1px;border-right:1px solid #999;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.markdown-preview pre.line-numbers .line-numbers-rows>span{pointer-events:none;display:block;counter-increment:linenumber}.markdown-preview pre.line-numbers .line-numbers-rows>span:before{content:counter(linenumber);color:#999;display:block;padding-right:.8em;text-align:right}.markdown-preview .mathjax-exps .MathJax_Display{text-align:center !important}.markdown-preview:not([for="preview"]) .code-chunk .btn-group{display:none}.markdown-preview:not([for="preview"]) .code-chunk .status{display:none}.markdown-preview:not([for="preview"]) .code-chunk .output-div{margin-bottom:16px}.scrollbar-style::-webkit-scrollbar{width:8px}.scrollbar-style::-webkit-scrollbar-track{border-radius:10px;background-color:transparent}.scrollbar-style::-webkit-scrollbar-thumb{border-radius:5px;background-color:rgba(150,150,150,0.66);border:4px solid rgba(150,150,150,0.66);background-clip:content-box}html body[for="html-export"]:not([data-presentation-mode]){position:relative;width:100%;height:100%;top:0;left:0;margin:0;padding:0;overflow:auto}html body[for="html-export"]:not([data-presentation-mode]) .markdown-preview{position:relative;top:0}@media screen and (min-width:914px){html body[for="html-export"]:not([data-presentation-mode]) .markdown-preview{padding:2em calc(50% - 457px + 2em)}}@media screen and (max-width:914px){html body[for="html-export"]:not([data-presentation-mode]) .markdown-preview{padding:2em}}@media screen and (max-width:450px){html body[for="html-export"]:not([data-presentation-mode]) .markdown-preview{font-size:14px !important;padding:1em}}@media print{html body[for="html-export"]:not([data-presentation-mode]) #sidebar-toc-btn{display:none}}html body[for="html-export"]:not([data-presentation-mode]) #sidebar-toc-btn{position:fixed;bottom:8px;left:8px;font-size:28px;cursor:pointer;color:inherit;z-index:99;width:32px;text-align:center;opacity:.4}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] #sidebar-toc-btn{opacity:1}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc{position:fixed;top:0;left:0;width:300px;height:100%;padding:32px 0 48px 0;font-size:14px;box-shadow:0 0 4px rgba(150,150,150,0.33);box-sizing:border-box;overflow:auto;background-color:inherit}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc::-webkit-scrollbar{width:8px}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc::-webkit-scrollbar-track{border-radius:10px;background-color:transparent}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc::-webkit-scrollbar-thumb{border-radius:5px;background-color:rgba(150,150,150,0.66);border:4px solid rgba(150,150,150,0.66);background-clip:content-box}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc a{text-decoration:none}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc ul{padding:0 1.6em;margin-top:.8em}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc li{margin-bottom:.8em}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc ul{list-style-type:none}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .markdown-preview{left:300px;width:calc(100% -  300px);padding:2em calc(50% - 457px -  150px);margin:0;box-sizing:border-box}@media screen and (max-width:1274px){html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .markdown-preview{padding:2em}}@media screen and (max-width:450px){html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .markdown-preview{width:100%}}html body[for="html-export"]:not([data-presentation-mode]):not([html-show-sidebar-toc]) .markdown-preview{left:50%;transform:translateX(-50%)}html body[for="html-export"]:not([data-presentation-mode]):not([html-show-sidebar-toc]) .md-sidebar-toc{display:none}/**
 * prism.js Github theme based on GitHub's theme.
 * @author Sam Clarke
 */
code[class*="language-"],
pre[class*="language-"] {
  color: #333;
  background: none;
  font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace;
  text-align: left;
  white-space: pre;
  word-spacing: normal;
  word-break: normal;
  word-wrap: normal;
  line-height: 1.4;

  -moz-tab-size: 8;
  -o-tab-size: 8;
  tab-size: 8;

  -webkit-hyphens: none;
  -moz-hyphens: none;
  -ms-hyphens: none;
  hyphens: none;
}

/* Code blocks */
pre[class*="language-"] {
  padding: .8em;
  overflow: auto;
  /* border: 1px solid #ddd; */
  border-radius: 3px;
  /* background: #fff; */
  background: #f5f5f5;
}

/* Inline code */
:not(pre) > code[class*="language-"] {
  padding: .1em;
  border-radius: .3em;
  white-space: normal;
  background: #f5f5f5;
}

.token.comment,
.token.blockquote {
  color: #969896;
}

.token.cdata {
  color: #183691;
}

.token.doctype,
.token.punctuation,
.token.variable,
.token.macro.property {
  color: #333;
}

.token.operator,
.token.important,
.token.keyword,
.token.rule,
.token.builtin {
  color: #a71d5d;
}

.token.string,
.token.url,
.token.regex,
.token.attr-value {
  color: #183691;
}

.token.property,
.token.number,
.token.boolean,
.token.entity,
.token.atrule,
.token.constant,
.token.symbol,
.token.command,
.token.code {
  color: #0086b3;
}

.token.tag,
.token.selector,
.token.prolog {
  color: #63a35c;
}

.token.function,
.token.namespace,
.token.pseudo-element,
.token.class,
.token.class-name,
.token.pseudo-class,
.token.id,
.token.url-reference .token.variable,
.token.attr-name {
  color: #795da3;
}

.token.entity {
  cursor: help;
}

.token.title,
.token.title .token.punctuation {
  font-weight: bold;
  color: #1d3e81;
}

.token.list {
  color: #ed6a43;
}

.token.inserted {
  background-color: #eaffea;
  color: #55a532;
}

.token.deleted {
  background-color: #ffecec;
  color: #bd2c00;
}

.token.bold {
  font-weight: bold;
}

.token.italic {
  font-style: italic;
}


/* JSON */
.language-json .token.property {
  color: #183691;
}

.language-markup .token.tag .token.punctuation {
  color: #333;
}

/* CSS */
code.language-css,
.language-css .token.function {
  color: #0086b3;
}

/* YAML */
.language-yaml .token.atrule {
  color: #63a35c;
}

code.language-yaml {
  color: #183691;
}

/* Ruby */
.language-ruby .token.function {
  color: #333;
}

/* Markdown */
.language-markdown .token.url {
  color: #795da3;
}

/* Makefile */
.language-makefile .token.symbol {
  color: #795da3;
}

.language-makefile .token.variable {
  color: #183691;
}

.language-makefile .token.builtin {
  color: #0086b3;
}

/* Bash */
.language-bash .token.keyword {
  color: #0086b3;
}

/* highlight */
pre[data-line] {
  position: relative;
  padding: 1em 0 1em 3em;
}
pre[data-line] .line-highlight-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  background-color: transparent;
  display: block;
  width: 100%;
}

pre[data-line] .line-highlight {
  position: absolute;
  left: 0;
  right: 0;
  padding: inherit 0;
  margin-top: 1em;
  background: hsla(24, 20%, 50%,.08);
  background: linear-gradient(to right, hsla(24, 20%, 50%,.1) 70%, hsla(24, 20%, 50%,0));
  pointer-events: none;
  line-height: inherit;
  white-space: pre;
}

pre[data-line] .line-highlight:before, 
pre[data-line] .line-highlight[data-end]:after {
  content: attr(data-start);
  position: absolute;
  top: .4em;
  left: .6em;
  min-width: 1em;
  padding: 0 .5em;
  background-color: hsla(24, 20%, 50%,.4);
  color: hsl(24, 20%, 95%);
  font: bold 65%/1.5 sans-serif;
  text-align: center;
  vertical-align: .3em;
  border-radius: 999px;
  text-shadow: none;
  box-shadow: 0 1px white;
}

pre[data-line] .line-highlight[data-end]:after {
  content: attr(data-end);
  top: auto;
  bottom: .4em;
}.emoji {
  height: 0.8em;
}html body{font-family:"Helvetica Neue",Helvetica,"Segoe UI",Arial,freesans,sans-serif;font-size:16px;line-height:1.6;color:#333;background-color:#fff;overflow:initial;box-sizing:border-box;word-wrap:break-word}html body>:first-child{margin-top:0}html body h1,html body h2,html body h3,html body h4,html body h5,html body h6{line-height:1.2;margin-top:1em;margin-bottom:16px;color:#000}html body h1{font-size:2.25em;font-weight:300;padding-bottom:.3em}html body h2{font-size:1.75em;font-weight:400;padding-bottom:.3em}html body h3{font-size:1.5em;font-weight:500}html body h4{font-size:1.25em;font-weight:600}html body h5{font-size:1.1em;font-weight:600}html body h6{font-size:1em;font-weight:600}html body h1,html body h2,html body h3,html body h4,html body h5{font-weight:600}html body h5{font-size:1em}html body h6{color:#5c5c5c}html body strong{color:#000}html body del{color:#5c5c5c}html body a:not([href]){color:inherit;text-decoration:none}html body a{color:#08c;text-decoration:none}html body a:hover{color:#00a3f5;text-decoration:none}html body img{max-width:100%}html body>p{margin-top:0;margin-bottom:16px;word-wrap:break-word}html body>ul,html body>ol{margin-bottom:16px}html body ul,html body ol{padding-left:2em}html body ul.no-list,html body ol.no-list{padding:0;list-style-type:none}html body ul ul,html body ul ol,html body ol ol,html body ol ul{margin-top:0;margin-bottom:0}html body li{margin-bottom:0}html body li.task-list-item{list-style:none}html body li>p{margin-top:0;margin-bottom:0}html body .task-list-item-checkbox{margin:0 .2em .25em -1.8em;vertical-align:middle}html body .task-list-item-checkbox:hover{cursor:pointer}html body blockquote{margin:16px 0;font-size:inherit;padding:0 15px;color:#5c5c5c;border-left:4px solid #d6d6d6}html body blockquote>:first-child{margin-top:0}html body blockquote>:last-child{margin-bottom:0}html body hr{height:4px;margin:32px 0;background-color:#d6d6d6;border:0 none}html body table{margin:10px 0 15px 0;border-collapse:collapse;border-spacing:0;display:block;width:100%;overflow:auto;word-break:normal;word-break:keep-all}html body table th{font-weight:bold;color:#000}html body table td,html body table th{border:1px solid #d6d6d6;padding:6px 13px}html body dl{padding:0}html body dl dt{padding:0;margin-top:16px;font-size:1em;font-style:italic;font-weight:bold}html body dl dd{padding:0 16px;margin-bottom:16px}html body code{font-family:Menlo,Monaco,Consolas,'Courier New',monospace;font-size:.85em !important;color:#000;background-color:#f0f0f0;border-radius:3px;padding:.2em 0}html body code::before,html body code::after{letter-spacing:-0.2em;content:"\00a0"}html body pre>code{padding:0;margin:0;font-size:.85em !important;word-break:normal;white-space:pre;background:transparent;border:0}html body .highlight{margin-bottom:16px}html body .highlight pre,html body pre{padding:1em;overflow:auto;font-size:.85em !important;line-height:1.45;border:#d6d6d6;border-radius:3px}html body .highlight pre{margin-bottom:0;word-break:normal}html body pre code,html body pre tt{display:inline;max-width:initial;padding:0;margin:0;overflow:initial;line-height:inherit;word-wrap:normal;background-color:transparent;border:0}html body pre code:before,html body pre tt:before,html body pre code:after,html body pre tt:after{content:normal}html body p,html body blockquote,html body ul,html body ol,html body dl,html body pre{margin-top:0;margin-bottom:16px}html body kbd{color:#000;border:1px solid #d6d6d6;border-bottom:2px solid #c7c7c7;padding:2px 4px;background-color:#f0f0f0;border-radius:3px}@media print{html body{background-color:#fff}html body h1,html body h2,html body h3,html body h4,html body h5,html body h6{color:#000;page-break-after:avoid}html body blockquote{color:#5c5c5c}html body pre{page-break-inside:avoid}html body table{display:table}html body img{display:block;max-width:100%;max-height:100%}html body pre,html body code{word-wrap:break-word;white-space:pre}}
    /* Please visit the URL below for more information: */
/*   https://shd101wyy.github.io/markdown-preview-enhanced/#/customize-css */

    </style>
    <link rel="stylesheet" href="file:///C:/Users/jueyue/.vscode/extensions/shd101wyy.markdown-preview-enhanced-0.4.3/node_modules/@shd101wyy/mume/dependencies/katex/katex.min.css">
  
  
    <div class="mume markdown-preview">
    <div><h1 class="mume-header" id="1" ebook-toc-level-1="" heading="1. &amp;#x524D;&amp;#x8A00;">1. 前言</h1>

<h2 class="mume-header" id="101" ebook-toc-level-2="" heading="1.1 &amp;#x524D;&amp;#x8A00;">1.1 前言</h2>

<p>easypoi功能如同名字easy,主打的功能就是容易,让一个没见接触过poi的人员<br>
就可以方便的写出Excel导出,Excel模板导出,Excel导入,Word模板导出,通过简单的注解和模板<br>
语言(熟悉的表达式语法),完成以前复杂的写法</p>
<pre class="language-text">官网：https://opensource.afterturn.cn/
邮箱： qrb.jueyue@foxmail.com
QQ群:  364192721
优秀团队,承接私活,加微信:13165188222 ,添加备注一众
</pre>
<p>不如poi那么自定义,不如jxl那么多标签,但是我们就是写的少,写的少</p>
<p><strong>EasyPoi的主要特点</strong></p>
<pre class="language-text">1.设计精巧,使用简单
2.接口丰富,扩展简单
3.默认值多,write less do more
4.spring mvc支持,web导出可以简单明了
</pre>
<p><strong>最好看看第10章常见问题</strong></p>
<p><strong>功能</strong></p>
<p>Excel自适应xls和xlsx两种格式,word只支持docx模式</p>
<p>1.Excel导入</p>
<ul>
<li>注解导入</li>
<li>Map导入</li>
<li>大数据量导入sax模式</li>
<li>导入文件保存</li>
<li>文件校验</li>
<li>字段校验</li>
</ul>
<p>2.Excel导出</p>
<ul>
<li>注解导出</li>
<li>模板导出</li>
<li>html导出</li>
</ul>
<p>3.Excel转html</p>
<p>4.word导出</p>
<p>5.pdf导出</p>
<h2 class="mume-header" id="102" ebook-toc-level-2="" heading="1.2 Easypoi&amp;#x4ECB;&amp;#x7ECD;">1.2 Easypoi介绍</h2>

<p>Easypoi 为谁而开发</p>
<ul>
<li>不太熟悉poi的</li>
<li>不想写太多重复太多的</li>
<li>只是简单的导入导出的</li>
<li>喜欢使用模板的</li>
</ul>
<p>都可以使用easypoi</p>
<p>Easypoi的目标是什么<br>
Easypoi的目标不是替代poi,而是让一个不懂导入导出的快速使用poi完成Excel和word的各种操作,而不是看很多api才可以完成这样工作</p>
<p>为什么会写Easypoi</p>
<p>以前的以前(岁月真TMD的快)我虽然写了不少代码但还是很少写poi,然后跳到一家公司之后就和业务人员聊上了,来这个需要个报表,这个报表样式是这样的,这个表头是这样的,就这样我写了大量的poi代码,每次都是大量的篇幅,copy to copy,无聊的一逼,然后加入了jeecg,jeecg中有一个小的工具类,虽然我也不知道是谁写的,然是可以用注解搞定最简单的导出,突然豁然开朗,我可以完善,让我从报表的苦海当中脱离出来,这样我花了一周的时间做了第一个版本支持导入导出放到了jeecg,发现还是不错的,慢慢的用的人越来越多,我就把这块独立出来了,再然后有人提出了模板,然后就加入了模板功能,提出了word的需求,加入了word的功能,后来工作忙了虽然没再参与jeecg,但还是一直维持这easypoi的更新,根据见识的增长也不断的重构这代码,直到现在</p>
<p>独特的功能</p>
<ul>
<li>基于注解的导入导出,修改注解就可以修改Excel</li>
<li>支持常用的样式自定义</li>
<li>基于map可以灵活定义的表头字段</li>
<li>支持一堆多的导出,导入</li>
<li>支持模板的导出,一些常见的标签,自定义标签</li>
<li>支持HTML/Excel转换,如果模板还不能满足用户的变态需求,请用这个功能</li>
<li>支持word的导出,支持图片,Excel</li>
</ul>
<p>小白如何开始</p>
<ul>
<li>下载demo运行看看,基本上常见的用用法都在里面<a href="https://gitee.com/lemur/easypoi-test">easypoi-test</a></li>
<li>查看几个*Util的用法,Easypoi的主要输出就是这个</li>
<li>看看注解的意思</li>
<li>看看模板的标签用法</li>
<li>可以出师了</li>
</ul>
<h2 class="mume-header" id="103" ebook-toc-level-2="" heading="1.3 &amp;#x4F7F;&amp;#x7528;">1.3 使用</h2>

<ul>
<li>1.easypoi 父包--作用大家都懂得</li>
<li>2.easypoi-annotation 基础注解包,作用与实体对象上,拆分后方便maven多工程的依赖管理</li>
<li>3.easypoi-base 导入导出的工具包,可以完成Excel导出,导入,Word的导出,Excel的导出功能</li>
<li>4.easypoi-web  耦合了spring-mvc 基于AbstractView,极大的简化spring-mvc下的导出功能</li>
<li>5.sax 导入使用xercesImpl这个包(这个包可能造成奇怪的问题哈),word导出使用poi-scratchpad,都作为可选包了</li>
</ul>
<p>如果不使用spring mvc的便捷福利,直接引入easypoi-base 就可以了,easypoi-annotation</p>
<p>如果使用maven,请使用如下坐标</p>
<pre data-role="codeBlock" data-info="xml" class="language-xml"> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">&gt;</span></span>cn.afterturn<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">&gt;</span></span>easypoi-base<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>version</span><span class="token punctuation">&gt;</span></span>4.1.0<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>version</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">&gt;</span></span>cn.afterturn<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">&gt;</span></span>easypoi-web<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>version</span><span class="token punctuation">&gt;</span></span>4.1.0<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>version</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">&gt;</span></span>cn.afterturn<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">&gt;</span></span>easypoi-annotation<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>version</span><span class="token punctuation">&gt;</span></span>4.1.0<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>version</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">&gt;</span></span>
</pre><p>如果没有maven请直接下jar,在<a href="http://maven.aliyun.com/nexus/#nexus-search;quick~easypoi">alimaven</a></p>
<h2 class="mume-header" id="104" ebook-toc-level-2="" heading="1.4 &amp;#x6D4B;&amp;#x8BD5;&amp;#x9879;&amp;#x76EE;">1.4 测试项目</h2>

<p>测试这个事情真不是个容易的事情<br>
测试项目包括两块 Junit 的常见测试和spring 的view测试</p>
<p><strong>1.spring view测试</strong><br>
运行application就可以了,访问界面,然后看到界面<br>
<img src="./easypoi_files/10230428_pMr5.png" alt="view" title="在这里输入图片标题"><br>
对应的代码在view下面</p>
<p><strong>2.Junit的测试目录结构如下</strong></p>
<ul>
<li>
<p>tohtml html预览测试</p>
</li>
<li>
<p>view 导出的view测试</p>
</li>
<li>
<p>cache 自定义缓存测试</p>
</li>
<li>
<p>html html互转测试</p>
</li>
<li>
<p>test</p>
<ul>
<li>excel
<ul>
<li>read 读取Excel测试
<ul>
<li>check 导入检查测试</li>
<li>hanlder 导入数据处理</li>
<li>img 含图片导入测试</li>
</ul>
</li>
</ul>
</li>
<li>styler 导出样式自定义测试</li>
<li>template 模板导出测试
<ul>
<li>sum 导出含统计测试</li>
</ul>
</li>
<li>test 导出测试
<ul>
<li>groupname groupname 属性测试</li>
<li>img 导出图片测试</li>
</ul>
</li>
</ul>
</li>
<li>
<p>pdf pdf测试</p>
</li>
<li>
<p>word word导出测试</p>
</li>
<li>
<p>util util 内部测试</p>
</li>
</ul>
<p>目前的测试覆盖率<br>
<img src="./easypoi_files/10230945_d2rq.png" alt="输入图片说明" title="在这里输入图片标题"></p>
<h2 class="mume-header" id="105" ebook-toc-level-2="" heading="1.5 &amp;#x53EF;&amp;#x80FD;&amp;#x5B58;&amp;#x5728;&amp;#x7684;&amp;#x5C0F;&amp;#x5751;">1.5 可能存在的小坑</h2>

<p><strong>缓存问题</strong><br>
缓存问题好像是很多童鞋都遇到的问题，可能是我设计的逻辑问题，但是一直没有好的解决，<br>
但是我也给了一个无奈的解决方案，大家可以自己实现接口IFileLoader</p>
<pre data-role="codeBlock" data-info="java" class="language-java"><span class="token keyword">public</span> <span class="token keyword">interface</span> <span class="token class-name">IFileLoader</span> <span class="token punctuation">{</span>
    <span class="token comment">/**
     * 可以自定义KEY的作用
     * @param key
     * @return
     */</span>
    <span class="token keyword">public</span> <span class="token keyword">byte</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token function">getFile</span><span class="token punctuation">(</span><span class="token class-name">String</span> key<span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token punctuation">}</span>
</pre><p>来自己获取自己的文件，用来解决文件获取不到的问题<br>
设置提供了两种方案，都是POICacheManager 的静态方法</p>
<pre data-role="codeBlock" data-info="java" class="language-java">    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">setFileLoder</span><span class="token punctuation">(</span><span class="token class-name">IFileLoader</span> fileLoder<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token class-name">POICacheManager</span><span class="token punctuation">.</span>fileLoder <span class="token operator">=</span> fileLoder<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token comment">/**
     * 一次线程有效
     * @param fileLoder
     */</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">setFileLoderOnce</span><span class="token punctuation">(</span><span class="token class-name">IFileLoader</span> fileLoder<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>fileLoder <span class="token operator">!=</span> <span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            LOCAL_FILELOADER<span class="token punctuation">.</span><span class="token function">set</span><span class="token punctuation">(</span>fileLoder<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
</pre><p>第一个是全局替换，可以在项目启动的时候，设置下就可以了，第一个是当前线程有效，希望可以帮助大家解决问题，我再研究下更通用的文件获取，或者那位朋友提供下自己的通用方案。</p>
<h2 class="mume-header" id="106" ebook-toc-level-2="" heading="1.6 &amp;#x6211;&amp;#x8BA4;&amp;#x4E3A;&amp;#x7684;&amp;#x6700;&amp;#x4F73;&amp;#x5B9E;&amp;#x8DF5; ,&amp;#x4EC0;&amp;#x4E48;&amp;#x60C5;&amp;#x51B5;&amp;#x8BE5;&amp;#x7528;&amp;#x90A3;&amp;#x4E2A;&amp;#x65B9;&amp;#x6CD5;">1.6 我认为的最佳实践 ,什么情况该用那个方法</h2>

<h3 class="mume-header" id="10601" ebook-toc-level-3="" heading="1.6.1 &amp;#x91CF;&amp;#x4E0D;&amp;#x5927;,&amp;#x8868;&amp;#x7B80;&amp;#x5355;&amp;#x7684;&amp;#x8BFB;&amp;#x5199;">1.6.1 量不大,表简单的读写</h3>

<p>使用下面几个方法</p>
<pre data-role="codeBlock" data-info="java" class="language-java"><span class="token comment">/**
     * Excel 导入 数据源本地文件,不返回校验结果 导入 字 段类型 Integer,Long,Double,Date,String,Boolean
     * 
     * @param file
     * @param pojoClass
     * @param params
     * @return
     */</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">&gt;</span></span> <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">&gt;</span></span> <span class="token function">importExcel</span><span class="token punctuation">(</span><span class="token class-name">File</span> file<span class="token punctuation">,</span> <span class="token class-name">Class</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span><span class="token punctuation">&gt;</span></span> pojoClass<span class="token punctuation">,</span> <span class="token class-name">ImportParams</span> params<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token class-name">FileInputStream</span> in <span class="token operator">=</span> <span class="token keyword">null</span><span class="token punctuation">;</span>
        <span class="token keyword">try</span> <span class="token punctuation">{</span>
            in <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">FileInputStream</span><span class="token punctuation">(</span>file<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">ExcelImportService</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">importExcelByIs</span><span class="token punctuation">(</span>in<span class="token punctuation">,</span> pojoClass<span class="token punctuation">,</span> params<span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getList</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">ExcelImportException</span> e<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">ExcelImportException</span><span class="token punctuation">(</span>e<span class="token punctuation">.</span><span class="token function">getType</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> e<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">Exception</span> e<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            LOGGER<span class="token punctuation">.</span><span class="token function">error</span><span class="token punctuation">(</span>e<span class="token punctuation">.</span><span class="token function">getMessage</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> e<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">ExcelImportException</span><span class="token punctuation">(</span>e<span class="token punctuation">.</span><span class="token function">getMessage</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> e<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span> <span class="token keyword">finally</span> <span class="token punctuation">{</span>
            <span class="token class-name">IOUtils</span><span class="token punctuation">.</span><span class="token function">closeQuietly</span><span class="token punctuation">(</span>in<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>

    <span class="token comment">/**
     * Excel 导入 数据源IO流,不返回校验结果 导入 字段类型 Integer,Long,Double,Date,String,Boolean
     * 
     * @param inputstream
     * @param pojoClass
     * @param params
     * @return
     * @throws Exception
     */</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">&gt;</span></span> <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">&gt;</span></span> <span class="token function">importExcel</span><span class="token punctuation">(</span><span class="token class-name">InputStream</span> inputstream<span class="token punctuation">,</span> <span class="token class-name">Class</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span><span class="token punctuation">&gt;</span></span> pojoClass<span class="token punctuation">,</span>
                                          <span class="token class-name">ImportParams</span> params<span class="token punctuation">)</span> <span class="token keyword">throws</span> <span class="token class-name">Exception</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">ExcelImportService</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">importExcelByIs</span><span class="token punctuation">(</span>inputstream<span class="token punctuation">,</span> pojoClass<span class="token punctuation">,</span> params<span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getList</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</pre><pre data-role="codeBlock" data-info="java" class="language-java">    <span class="token comment">/**
     * @param entity    表格标题属性
     * @param pojoClass Excel对象Class
     * @param dataSet   Excel对象数据List
     */</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token class-name">Workbook</span> <span class="token function">exportExcel</span><span class="token punctuation">(</span><span class="token class-name">ExportParams</span> entity<span class="token punctuation">,</span> <span class="token class-name">Class</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span><span class="token punctuation">&gt;</span></span> pojoClass<span class="token punctuation">,</span>
                                       <span class="token class-name">Collection</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span><span class="token punctuation">&gt;</span></span> dataSet<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token class-name">Workbook</span> workbook <span class="token operator">=</span> <span class="token function">getWorkbook</span><span class="token punctuation">(</span>entity<span class="token punctuation">.</span><span class="token function">getType</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> dataSet<span class="token punctuation">.</span><span class="token function">size</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">new</span> <span class="token class-name">ExcelExportService</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">createSheet</span><span class="token punctuation">(</span>workbook<span class="token punctuation">,</span> entity<span class="token punctuation">,</span> pojoClass<span class="token punctuation">,</span> dataSet<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">return</span> workbook<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</pre><h3 class="mume-header" id="10602" ebook-toc-level-3="" heading="1.6.2 &amp;#x5BF9;&amp;#x8C61;&amp;#x4E0D;&amp;#x56FA;&amp;#x5B9A;&amp;#x7684;&amp;#x5BFC;&amp;#x5165;&amp;#x5BFC;&amp;#x51FA;">1.6.2 对象不固定的导入导出</h3>

<p>导出使用自己构造ExcelExportEntity,导入的话对象改成map就可以了</p>
<pre data-role="codeBlock" data-info="java" class="language-java"><span class="token comment">/**
     * 根据Map创建对应的Excel
     *
     * @param entity     表格标题属性
     * @param entityList Map对象列表
     * @param dataSet    Excel对象数据List
     */</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token class-name">Workbook</span> <span class="token function">exportExcel</span><span class="token punctuation">(</span><span class="token class-name">ExportParams</span> entity<span class="token punctuation">,</span> <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">ExcelExportEntity</span><span class="token punctuation">&gt;</span></span> entityList<span class="token punctuation">,</span>
                                       <span class="token class-name">Collection</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span><span class="token punctuation">&gt;</span></span> dataSet<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token class-name">Workbook</span> workbook <span class="token operator">=</span> <span class="token function">getWorkbook</span><span class="token punctuation">(</span>entity<span class="token punctuation">.</span><span class="token function">getType</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> dataSet<span class="token punctuation">.</span><span class="token function">size</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">;</span>
        <span class="token keyword">new</span> <span class="token class-name">ExcelExportService</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">createSheetForMap</span><span class="token punctuation">(</span>workbook<span class="token punctuation">,</span> entity<span class="token punctuation">,</span> entityList<span class="token punctuation">,</span> dataSet<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">return</span> workbook<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</pre><p>导入还是上面方法,entity选择map就可以了,展示下map转Key,方便下一步处理</p>
<pre data-role="codeBlock" data-info="java" class="language-java">    <span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">MapImportHandler</span> <span class="token keyword">extends</span> <span class="token class-name">ExcelDataHandlerDefaultImpl</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Map</span><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span><span class="token punctuation">&gt;</span></span> <span class="token punctuation">{</span>

        <span class="token annotation punctuation">@Override</span>
        <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">setMapValue</span><span class="token punctuation">(</span><span class="token class-name">Map</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span></span> map<span class="token punctuation">,</span> <span class="token class-name">String</span> originKey<span class="token punctuation">,</span> <span class="token class-name">Object</span> value<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">if</span> <span class="token punctuation">(</span>value <span class="token keyword">instanceof</span> <span class="token class-name">Double</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token function">getRealKey</span><span class="token punctuation">(</span>originKey<span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token class-name">PoiPublicUtil</span><span class="token punctuation">.</span><span class="token function">doubleToString</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token class-name">Double</span><span class="token punctuation">)</span> value<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
                map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token function">getRealKey</span><span class="token punctuation">(</span>originKey<span class="token punctuation">)</span><span class="token punctuation">,</span> value <span class="token operator">!=</span> <span class="token keyword">null</span> <span class="token operator">?</span> value<span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">:</span> <span class="token keyword">null</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>

        <span class="token keyword">private</span> <span class="token class-name">String</span> <span class="token function">getRealKey</span><span class="token punctuation">(</span><span class="token class-name">String</span> originKey<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">if</span> <span class="token punctuation">(</span>originKey<span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span><span class="token string">"姓名"</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token keyword">return</span> <span class="token string">"name"</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
            <span class="token keyword">if</span> <span class="token punctuation">(</span>originKey<span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span><span class="token string">"身份证"</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token keyword">return</span> <span class="token string">"sfz"</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
            <span class="token keyword">if</span> <span class="token punctuation">(</span>originKey<span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span><span class="token string">"班主任寄语"</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token keyword">return</span> <span class="token string">"content"</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
            <span class="token keyword">if</span> <span class="token punctuation">(</span>originKey<span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span><span class="token string">"学科"</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token keyword">return</span> <span class="token string">"subjectName"</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
            <span class="token keyword">if</span> <span class="token punctuation">(</span>originKey<span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span><span class="token string">"学科成绩"</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token keyword">return</span> <span class="token string">"subjectScore"</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
            <span class="token keyword">if</span> <span class="token punctuation">(</span>originKey<span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span><span class="token string">"子学科"</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token keyword">return</span> <span class="token string">"childSubjectName"</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
            <span class="token keyword">if</span> <span class="token punctuation">(</span>originKey<span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span><span class="token string">"子学科成绩"</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token keyword">return</span> <span class="token string">"childSubjectScore"</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
            <span class="token keyword">return</span> originKey<span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
</pre><h3 class="mume-header" id="10603" ebook-toc-level-3="" heading="1.6.3 &amp;#x91CF;&amp;#x7A0D;&amp;#x5FAE;&amp;#x6709;&amp;#x70B9;&amp;#x5927;10W&amp;#x5185;">1.6.3 量稍微有点大10W内</h3>

<p>依然建议上面的写法,但不建议使用校验,可以加入下面参数加快时间,但是因为是一次返回可能量还是有点大,不支持一对多</p>
<pre data-role="codeBlock" data-info="java" class="language-java"> <span class="token comment">/**
     * 是否并行计算
     */</span>
    <span class="token keyword">private</span> <span class="token keyword">boolean</span>             concurrentTask <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">;</span>
</pre><p>写出基本上不用改,10W以上会自己使用SXSSFWorkbook,不支持图片了等其他一些特性,速度回快一些可以使用USE_SXSSF_LIMIT这个参数调教</p>
<h3 class="mume-header" id="10604" ebook-toc-level-3="" heading="1.6.4 &amp;#x66F4;&amp;#x5927;&amp;#x91CF;&amp;#x7684;&amp;#x8BFB;&amp;#x53D6;,&amp;#x6216;&amp;#x8005;&amp;#x9700;&amp;#x8981;&amp;#x6821;&amp;#x9A8C;&amp;#x7B49;&amp;#x65F6;&amp;#x95F4;&amp;#x7A0D;&amp;#x957F;,&amp;#x6216;&amp;#x8005;&amp;#x9891;&amp;#x7E41;&amp;#x5BFC;&amp;#x5165;&amp;#x5BB9;&amp;#x6613;&amp;#x5185;&amp;#x5B58;&amp;#x6EA2;&amp;#x51FA;">1.6.4 更大量的读取,或者需要校验等时间稍长,或者频繁导入容易内存溢出</h3>

<p>那就使用sax吧,这个更加高效,低内存但是支持较少</p>
<pre data-role="codeBlock" data-info="java" class="language-java"><span class="token comment">/**
     * Excel 通过SAX解析方法,适合大数据导入,不支持图片
     * 导入 数据源本地文件,不返回校验结果 导入 字 段类型 Integer,Long,Double,Date,String,Boolean
     * 
     * @param inputstream
     * @param pojoClass
     * @param params
     * @param handler
     */</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">importExcelBySax</span><span class="token punctuation">(</span><span class="token class-name">InputStream</span> inputstream<span class="token punctuation">,</span> <span class="token class-name">Class</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span><span class="token punctuation">&gt;</span></span> pojoClass<span class="token punctuation">,</span>
                                        <span class="token class-name">ImportParams</span> params<span class="token punctuation">,</span> <span class="token class-name">IReadHandler</span> handler<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">new</span> <span class="token class-name">SaxReadExcel</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">readExcel</span><span class="token punctuation">(</span>inputstream<span class="token punctuation">,</span> pojoClass<span class="token punctuation">,</span> params<span class="token punctuation">,</span> handler<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</pre><p>不在处理完在回调,而是每处理一行就回答一次的方式方便大家更快的同步入库或者处理异常</p>
<pre data-role="codeBlock" data-info="java" class="language-java">    <span class="token annotation punctuation">@Test</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">test</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">try</span> <span class="token punctuation">{</span>
            <span class="token class-name">ImportParams</span> params <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ImportParams</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            params<span class="token punctuation">.</span><span class="token function">setTitleRows</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            params<span class="token punctuation">.</span><span class="token function">setStartSheetIndex</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">long</span> start <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getTime</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token class-name">ExcelImportUtil</span><span class="token punctuation">.</span><span class="token function">importExcelBySax</span><span class="token punctuation">(</span>
                    <span class="token keyword">new</span> <span class="token class-name">FileInputStream</span><span class="token punctuation">(</span>
                            <span class="token keyword">new</span> <span class="token class-name">File</span><span class="token punctuation">(</span><span class="token class-name">FileUtilTest</span><span class="token punctuation">.</span><span class="token function">getWebRootPath</span><span class="token punctuation">(</span><span class="token string">"import/saxtest.xlsx"</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                    <span class="token class-name">Map</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">,</span> params<span class="token punctuation">,</span> 
                    <span class="token comment">// 这个是匿名类,不建议这样,最好还是自己实现一个类方便开发管理,泛型参数</span>
                    <span class="token keyword">new</span> <span class="token class-name">IReadHandler</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Map</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                        <span class="token annotation punctuation">@Override</span>
                        <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">handler</span><span class="token punctuation">(</span><span class="token class-name">Map</span> o<span class="token punctuation">)</span> <span class="token punctuation">{</span>
                            <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>o<span class="token punctuation">)</span><span class="token punctuation">;</span>
                        <span class="token punctuation">}</span>
                        <span class="token comment">// 所有数据执行完毕会调用这个类</span>
                        <span class="token annotation punctuation">@Override</span>
                        <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">doAfterAll</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                            <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"全部执行完毕了--------------------------------"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                        <span class="token punctuation">}</span>
                    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">FileNotFoundException</span> e<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            e<span class="token punctuation">.</span><span class="token function">printStackTrace</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
</pre><p>针对大数据量推荐方式是如下,每隔一段处理一次,cpu和内存都可以稳定在一定的范围内</p>
<pre data-role="codeBlock" data-info="java" class="language-java"><span class="token keyword">new</span> <span class="token class-name">IReadHandler</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Map</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>

    <span class="token keyword">private</span> <span class="token class-name">List</span> list <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ArrayList</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">handler</span><span class="token punctuation">(</span><span class="token class-name">Map</span> o<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        list<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>o<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">if</span><span class="token punctuation">(</span>list<span class="token punctuation">.</span>size <span class="token operator">==</span> <span class="token number">1000</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
            <span class="token function">handlerData</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
    <span class="token comment">// 所有数据执行完毕会调用这个类</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">doAfterAll</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token function">handlerData</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">private</span> <span class="token keyword">void</span> <span class="token function">handlerData</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token comment">//sava 或者其他操作</span>
        <span class="token function">save</span><span class="token punctuation">(</span>list<span class="token punctuation">)</span><span class="token punctuation">;</span>
        list<span class="token punctuation">.</span><span class="token function">clear</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

</pre><h3 class="mume-header" id="10605" ebook-toc-level-3="" heading="1.6.5 &amp;#x66F4;&amp;#x52A0;&amp;#x5927;&amp;#x91CF;&amp;#x7684;&amp;#x6570;&amp;#x636E;,&amp;#x767E;&amp;#x4E07;&amp;#x7EA7;&amp;#x4EE5;&amp;#x4E0A;">1.6.5 更加大量的数据,百万级以上</h3>

<p>使用csv把,这个靠谱的多,百万级读取数据也相当的快,内存也不高</p>
<pre data-role="codeBlock" data-info="java" class="language-java">    <span class="token comment">/**
     * Csv 导入流适合大数据导入
     * 导入 数据源IO流,不返回校验结果 导入 字段类型 Integer,Long,Double,Date,String,Boolean
     *
     * @param inputstream
     * @param pojoClass
     * @param params
     * @return
     */</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">&gt;</span></span> <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">&gt;</span></span> <span class="token function">importCsv</span><span class="token punctuation">(</span><span class="token class-name">InputStream</span> inputstream<span class="token punctuation">,</span> <span class="token class-name">Class</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span><span class="token punctuation">&gt;</span></span> pojoClass<span class="token punctuation">,</span>
                                        <span class="token class-name">CsvImportParams</span> params<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">CsvImportService</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">readExcel</span><span class="token punctuation">(</span>inputstream<span class="token punctuation">,</span> pojoClass<span class="token punctuation">,</span> params<span class="token punctuation">,</span> <span class="token keyword">null</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token comment">/**
     * Csv 导入流适合大数据导入
     * 导入 数据源IO流,不返回校验结果 导入 字段类型 Integer,Long,Double,Date,String,Boolean
     *
     * @param inputstream
     * @param pojoClass
     * @param params
     * @return
     */</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">importCsv</span><span class="token punctuation">(</span><span class="token class-name">InputStream</span> inputstream<span class="token punctuation">,</span> <span class="token class-name">Class</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span><span class="token punctuation">&gt;</span></span> pojoClass<span class="token punctuation">,</span>
                                        <span class="token class-name">CsvImportParams</span> params<span class="token punctuation">,</span> <span class="token class-name">IReadHandler</span> readHandler<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">new</span> <span class="token class-name">CsvImportService</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">readExcel</span><span class="token punctuation">(</span>inputstream<span class="token punctuation">,</span> pojoClass<span class="token punctuation">,</span> params<span class="token punctuation">,</span> readHandler<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token comment">/**
     * @param params    表格标题属性
     * @param pojoClass Excel对象Class
     * @param dataSet   Excel对象数据List
     */</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">exportCsv</span><span class="token punctuation">(</span><span class="token class-name">CsvExportParams</span> params<span class="token punctuation">,</span> <span class="token class-name">Class</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span><span class="token punctuation">&gt;</span></span> pojoClass<span class="token punctuation">,</span>
                                 <span class="token class-name">Collection</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span><span class="token punctuation">&gt;</span></span> dataSet<span class="token punctuation">,</span> <span class="token class-name">OutputStream</span> outputStream<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">new</span> <span class="token class-name">CsvExportService</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">createCsv</span><span class="token punctuation">(</span>outputStream<span class="token punctuation">,</span> params<span class="token punctuation">,</span> pojoClass<span class="token punctuation">,</span> dataSet<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token comment">/**
     * 根据Map创建对应的Excel
     *
     * @param params     表格标题属性
     * @param entityList Map对象列表
     * @param dataSet    Excel对象数据List
     */</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">exportCsv</span><span class="token punctuation">(</span><span class="token class-name">CsvExportParams</span> params<span class="token punctuation">,</span> <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">ExcelExportEntity</span><span class="token punctuation">&gt;</span></span> entityList<span class="token punctuation">,</span>
                                 <span class="token class-name">Collection</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span><span class="token punctuation">&gt;</span></span> dataSet<span class="token punctuation">,</span> <span class="token class-name">OutputStream</span> outputStream<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">new</span> <span class="token class-name">CsvExportService</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">createCsvOfList</span><span class="token punctuation">(</span>outputStream<span class="token punctuation">,</span> params<span class="token punctuation">,</span> entityList<span class="token punctuation">,</span> dataSet<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</pre><h3 class="mume-header" id="10606" ebook-toc-level-3="" heading="1.6.6 &amp;#x6A21;&amp;#x677F;&amp;#x9002;&amp;#x5408;&amp;#x5728;&amp;#x4EC0;&amp;#x4E48;&amp;#x73AF;&amp;#x5883;">1.6.6 模板适合在什么环境</h3>

<pre class="language-text">- 样式比较复杂
- excel格式也复杂
- 多个excel拼接
- 懒得自己写代码
</pre>
<h1 class="mume-header" id="2" ebook-toc-level-1="" heading="2.Excel&amp;#x6CE8;&amp;#x89E3;&amp;#x7248;">2.Excel注解版</h1>

<h2 class="mume-header" id="201" ebook-toc-level-2="" heading="2.1 Excel&amp;#x5BFC;&amp;#x5165;&amp;#x5BFC;&amp;#x51FA;">2.1 Excel导入导出</h2>

<p>Excel的导入导出是Easypoi的核心功能,前期基本也是围绕这个打造的,主要分为三种方式的处理,其中模板和Html目前只支持导出,因为支持Map.class其实导入应该是怎样都支持的</p>
<ul>
<li>注解方式,注解变种方式</li>
<li>模板方式</li>
<li>Html方式</li>
</ul>
<p>下面分别就这三种方式进行讲解</p>
<h2 class="mume-header" id="202" ebook-toc-level-2="" heading="2.2 &amp;#x6CE8;&amp;#x89E3;">2.2 注解</h2>

<h3 class="mume-header" id="40201" ebook-toc-level-3="" heading="&amp;#x6CE8;&amp;#x89E3;&amp;#x4ECB;&amp;#x7ECD;">注解介绍</h3>

<p>easypoi起因就是Excel的导入导出,最初的模板是实体和Excel的对应,model--row,filed--col 这样利用注解我们可以和容易做到excel到导入导出<br>
经过一段时间发展,现在注解有5个类分别是</p>
<ul>
<li>@Excel 作用到filed上面,是对Excel一列的一个描述</li>
<li>@ExcelCollection 表示一个集合,主要针对一对多的导出,比如一个老师对应多个科目,科目就可以用集合表示</li>
<li>@ExcelEntity 表示一个继续深入导出的实体,但他没有太多的实际意义,只是告诉系统这个对象里面同样有导出的字段</li>
<li>@ExcelIgnore 和名字一样表示这个字段被忽略跳过这个导导出</li>
<li>@ExcelTarget 这个是作用于最外层的对象,描述这个对象的id,以便支持一个对象可以针对不同导出做出不同处理</li>
</ul>
<p>注解中的ID的用法<br>
这个ID算是一个比较独特的例子,比如</p>
<pre data-role="codeBlock" data-info="java" class="language-java"><span class="token annotation punctuation">@ExcelTarget</span><span class="token punctuation">(</span><span class="token string">"teacherEntity"</span><span class="token punctuation">)</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">TeacherEntity</span> <span class="token keyword">implements</span> java<span class="token punctuation">.</span>io<span class="token punctuation">.</span><span class="token class-name">Serializable</span> <span class="token punctuation">{</span>
    <span class="token comment">/** name */</span>
    <span class="token annotation punctuation">@Excel</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">"主讲老师_teacherEntity,代课老师_absent"</span><span class="token punctuation">,</span> orderNum <span class="token operator">=</span> <span class="token string">"1"</span><span class="token punctuation">,</span> mergeVertical <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">,</span>needMerge<span class="token operator">=</span><span class="token boolean">true</span><span class="token punctuation">,</span>isImportField <span class="token operator">=</span> <span class="token string">"true_major,true_absent"</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token class-name">String</span> name<span class="token punctuation">;</span>
</pre><p>这里的@ExcelTarget 表示使用teacherEntity这个对象是可以针对不同字段做不同处理<br>
同样的ExcelEntity 和ExcelCollection 都支持这种方式<br>
当导出这对象时,name这一列对应的是主讲老师,而不是代课老师还有很多字段都支持这种做法</p>
<h3 class="mume-header" id="40202" ebook-toc-level-3="" heading="@Excel">@Excel</h3>

<p>这个是必须使用的注解,如果需求简单只使用这一个注解也是可以的,涵盖了常用的Excel需求,需要大家熟悉这个功能,主要分为基础,图片处理,时间处理,合并处理几块,name_id是上面讲的id用法,这里就不累言了</p>
<table>
<thead>
<tr>
<th>属性</th>
<th>类型</th>
<th>默认值</th>
<th>功能</th>
</tr>
</thead>
<tbody>
<tr>
<td>name</td>
<td>String</td>
<td>null</td>
<td>列名,支持name_id</td>
</tr>
<tr>
<td>needMerge</td>
<td>boolean</td>
<td>fasle</td>
<td>是否需要纵向合并单元格(用于含有list中,单个的单元格,合并list创建的多个row)</td>
</tr>
<tr>
<td>orderNum</td>
<td>String</td>
<td>"0"</td>
<td>列的排序,支持name_id</td>
</tr>
<tr>
<td>replace</td>
<td>String[]</td>
<td>{}</td>
<td>值得替换  导出是{a_id,b_id} 导入反过来</td>
</tr>
<tr>
<td>savePath</td>
<td>String</td>
<td>"upload"</td>
<td>导入文件保存路径,如果是图片可以填写,默认是upload/className/ IconEntity这个类对应的就是upload/Icon/</td>
</tr>
<tr>
<td>type</td>
<td>int</td>
<td>1</td>
<td>导出类型 1 是文本 2 是图片,3 是函数,10 是数字 默认是文本</td>
</tr>
<tr>
<td>width</td>
<td>double</td>
<td>10</td>
<td>列宽</td>
</tr>
<tr>
<td>height</td>
<td>double</td>
<td>10</td>
<td><strong>列高,后期打算统一使用@ExcelTarget的height,这个会被废弃,注意</strong></td>
</tr>
<tr>
<td>isStatistics</td>
<td>boolean</td>
<td>fasle</td>
<td>自动统计数据,在追加一行统计,把所有数据都和输出[这个处理会吞没异常,请注意这一点]</td>
</tr>
<tr>
<td>isHyperlink</td>
<td>boolean</td>
<td>false</td>
<td>超链接,如果是需要实现接口返回对象</td>
</tr>
<tr>
<td>isImportField</td>
<td>boolean</td>
<td>true</td>
<td>校验字段,看看这个字段是不是导入的Excel中有,如果没有说明是错误的Excel,读取失败,支持name_id</td>
</tr>
<tr>
<td>exportFormat</td>
<td>String</td>
<td>""</td>
<td>导出的时间格式,以这个是否为空来判断是否需要格式化日期</td>
</tr>
<tr>
<td>importFormat</td>
<td>String</td>
<td>""</td>
<td>导入的时间格式,以这个是否为空来判断是否需要格式化日期</td>
</tr>
<tr>
<td>format</td>
<td>String</td>
<td>""</td>
<td>时间格式,相当于同时设置了exportFormat 和 importFormat</td>
</tr>
<tr>
<td>databaseFormat</td>
<td>String</td>
<td>"yyyyMMddHHmmss"</td>
<td>导出时间设置,如果字段是Date类型则不需要设置 数据库如果是string 类型,这个需要设置这个数据库格式,用以转换时间格式输出</td>
</tr>
<tr>
<td>numFormat</td>
<td>String</td>
<td>""</td>
<td>数字格式化,参数是Pattern,使用的对象是DecimalFormat</td>
</tr>
<tr>
<td>imageType</td>
<td>int</td>
<td>1</td>
<td>导出类型 1 从file读取 2 是从数据库中读取 默认是文件 同样导入也是一样的</td>
</tr>
<tr>
<td>suffix</td>
<td>String</td>
<td>""</td>
<td>文字后缀,如% 90 变成90%</td>
</tr>
<tr>
<td>isWrap</td>
<td>boolean</td>
<td>true</td>
<td>是否换行 即支持\n</td>
</tr>
<tr>
<td>mergeRely</td>
<td>int[]</td>
<td>{}</td>
<td>合并单元格依赖关系,比如第二列合并是基于第一列 则{0}就可以了</td>
</tr>
<tr>
<td>mergeVertical</td>
<td>boolean</td>
<td>fasle</td>
<td>纵向合并内容相同的单元格</td>
</tr>
<tr>
<td>fixedIndex</td>
<td>int</td>
<td>-1</td>
<td>对应excel的列,忽略名字</td>
</tr>
<tr>
<td>isColumnHidden</td>
<td>boolean</td>
<td>false</td>
<td>导出隐藏列</td>
</tr>
</tbody>
</table>
<h3 class="mume-header" id="40203" ebook-toc-level-3="" heading="@ExcelCollection">@ExcelCollection</h3>

<p>一对多的集合注解,用以标记集合是否被数据以及集合的整体排序</p>
<table>
<thead>
<tr>
<th>属性</th>
<th>类型</th>
<th>默认值</th>
<th>功能</th>
</tr>
</thead>
<tbody>
<tr>
<td>id</td>
<td>String</td>
<td>null</td>
<td>定义ID</td>
</tr>
<tr>
<td>name</td>
<td>String</td>
<td>null</td>
<td>定义集合列名,支持nanm_id</td>
</tr>
<tr>
<td>orderNum</td>
<td>int</td>
<td>0</td>
<td>排序,支持name_id</td>
</tr>
<tr>
<td>type</td>
<td>Class&lt;?&gt;</td>
<td>ArrayList.class</td>
<td>导入时创建对象使用</td>
</tr>
</tbody>
</table>
<h3 class="mume-header" id="40204" ebook-toc-level-3="" heading="@ExcelEntity">@ExcelEntity</h3>

<p>标记是不是导出excel 标记为实体类,一遍是一个内部属性类,标记是否继续穿透,可以自定义内部id</p>
<table>
<thead>
<tr>
<th>属性</th>
<th>类型</th>
<th>默认值</th>
<th>功能</th>
</tr>
</thead>
<tbody>
<tr>
<td>id</td>
<td>String</td>
<td>null</td>
<td>定义ID</td>
</tr>
</tbody>
</table>
<h3 class="mume-header" id="40205" ebook-toc-level-3="" heading="@ExcelIgnore">@ExcelIgnore</h3>

<p>忽略这个属性,多使用需循环引用中,无需多解释吧^^</p>
<h3 class="mume-header" id="40206" ebook-toc-level-3="" heading="@ExcelTarget">@ExcelTarget</h3>

<p>限定一个到处实体的注解,以及一些通用设置,作用于最外面的实体</p>
<table>
<thead>
<tr>
<th>属性</th>
<th>类型</th>
<th>默认值</th>
<th>功能</th>
</tr>
</thead>
<tbody>
<tr>
<td>value</td>
<td>String</td>
<td>null</td>
<td>定义ID</td>
</tr>
<tr>
<td>height</td>
<td>double</td>
<td>10</td>
<td>设置行高</td>
</tr>
<tr>
<td>fontSize</td>
<td>short</td>
<td>11</td>
<td>设置文字大小</td>
</tr>
</tbody>
</table>
<h1 class="mume-header" id="3" ebook-toc-level-1="" heading="2.3 &amp;#x6CE8;&amp;#x89E3;&amp;#x5BFC;&amp;#x51FA;,&amp;#x5BFC;&amp;#x5165;">2.3 注解导出,导入</h1>

<h3 class="mume-header" id="301" ebook-toc-level-3="" heading="2.3.1 &amp;#x5BF9;&amp;#x8C61;&amp;#x5B9A;&amp;#x4E49;">2.3.1 对象定义</h3>

<p>注解介绍了这么多,大家基本上也了解我们的注解是如何定义Excel的了吧,下面我们来跟着路飞实战吧<br>
这天老师吧路飞叫到了办公室,让给给老师实现一个报表的需求,就是从教育平台把某个班级的人员导出来<br>
需求是,导出我们班的所有学生的姓名,性别,出生日期,进校日期<br>
正巧路飞刚看到Easypo,就打算用Easypoi来实现,实现方法如下:</p>
<p>首先定义一个我们导出的对象,<strong><em>为了节省篇幅,统一忽略getter,setter</em></strong></p>
<pre data-role="codeBlock" data-info="java" class="language-java"> <span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">StudentEntity</span> <span class="token keyword">implements</span> java<span class="token punctuation">.</span>io<span class="token punctuation">.</span><span class="token class-name">Serializable</span> <span class="token punctuation">{</span>
    <span class="token comment">/**
     * id
     */</span>
    <span class="token keyword">private</span> <span class="token class-name">String</span>        id<span class="token punctuation">;</span>
    <span class="token comment">/**
     * 学生姓名
     */</span>
    <span class="token annotation punctuation">@Excel</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">"学生姓名"</span><span class="token punctuation">,</span> height <span class="token operator">=</span> <span class="token number">20</span><span class="token punctuation">,</span> width <span class="token operator">=</span> <span class="token number">30</span><span class="token punctuation">,</span> isImportField <span class="token operator">=</span> <span class="token string">"true_st"</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token class-name">String</span>        name<span class="token punctuation">;</span>
    <span class="token comment">/**
     * 学生性别
     */</span>
    <span class="token annotation punctuation">@Excel</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">"学生性别"</span><span class="token punctuation">,</span> replace <span class="token operator">=</span> <span class="token punctuation">{</span> <span class="token string">"男_1"</span><span class="token punctuation">,</span> <span class="token string">"女_2"</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> suffix <span class="token operator">=</span> <span class="token string">"生"</span><span class="token punctuation">,</span> isImportField <span class="token operator">=</span> <span class="token string">"true_st"</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token keyword">int</span>           sex<span class="token punctuation">;</span>

    <span class="token annotation punctuation">@Excel</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">"出生日期"</span><span class="token punctuation">,</span> databaseFormat <span class="token operator">=</span> <span class="token string">"yyyyMMddHHmmss"</span><span class="token punctuation">,</span> format <span class="token operator">=</span> <span class="token string">"yyyy-MM-dd"</span><span class="token punctuation">,</span> isImportField <span class="token operator">=</span> <span class="token string">"true_st"</span><span class="token punctuation">,</span> width <span class="token operator">=</span> <span class="token number">20</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token class-name">Date</span>          birthday<span class="token punctuation">;</span>

    <span class="token annotation punctuation">@Excel</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">"进校日期"</span><span class="token punctuation">,</span> databaseFormat <span class="token operator">=</span> <span class="token string">"yyyyMMddHHmmss"</span><span class="token punctuation">,</span> format <span class="token operator">=</span> <span class="token string">"yyyy-MM-dd"</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token class-name">Date</span> registrationDate<span class="token punctuation">;</span>
    
 <span class="token punctuation">}</span>
</pre><p>这里设置我们的4列分别是学生姓名,学生性别,出生日期,进校日期<br>
其中学生姓名定义了我们的列的行高,学生性别因为我们基本上都是存在数据库都是数字所以我们转换下,两个日期我们都是进行了格式化输出了,这样我们就完成了业务对我们Excel的样式需求,后面只有把这个学生列表输出就可以了<br>
生成Excel代码如下</p>
<pre data-role="codeBlock" data-info="java" class="language-java"> <span class="token class-name">Workbook</span> workbook <span class="token operator">=</span> <span class="token class-name">ExcelExportUtil</span><span class="token punctuation">.</span><span class="token function">exportExcel</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">ExportParams</span><span class="token punctuation">(</span><span class="token string">"计算机一班学生"</span><span class="token punctuation">,</span><span class="token string">"学生"</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
            <span class="token class-name">StudentEntity</span> <span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">,</span> list<span class="token punctuation">)</span><span class="token punctuation">;</span>
</pre><p>这样我们就得到的一个java中的Excel,然后把这个输出就得到我们的Excel了https://static.oschina.net/uploads/space/2017/0622/212811_uh7e_1157922.png</p>
<p><img src="./easypoi_files/212811_uh7e_1157922.png" alt=""></p>
<h3 class="mume-header" id="90101" ebook-toc-level-3="" heading="2.3.2 &amp;#x96C6;&amp;#x5408;&amp;#x5B9A;&amp;#x4E49;">2.3.2 集合定义</h3>

<p>路飞很快的完成了老师的任务,花了也就是喝杯茶的时间,就交差了,但过了一会就又被老师叫去了,让他给出一个某个班级选择选择某些课的学生以及对应的老师<br>
路飞又很快的想到了Easypoi,其中有一对多的导出,这不正是一对多的体现吗,然后他继续定义实体:<br>
一个课程对应一个老师<br>
一个课程对应N个学生<br>
课程的实体</p>
<pre data-role="codeBlock" data-info="java" class="language-java"> <span class="token annotation punctuation">@ExcelTarget</span><span class="token punctuation">(</span><span class="token string">"courseEntity"</span><span class="token punctuation">)</span>
 <span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">CourseEntity</span> <span class="token keyword">implements</span> java<span class="token punctuation">.</span>io<span class="token punctuation">.</span><span class="token class-name">Serializable</span> <span class="token punctuation">{</span>
    <span class="token comment">/** 主键 */</span>
    <span class="token keyword">private</span> <span class="token class-name">String</span>        id<span class="token punctuation">;</span>
    <span class="token comment">/** 课程名称 */</span>
    <span class="token annotation punctuation">@Excel</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">"课程名称"</span><span class="token punctuation">,</span> orderNum <span class="token operator">=</span> <span class="token string">"1"</span><span class="token punctuation">,</span> width <span class="token operator">=</span> <span class="token number">25</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token class-name">String</span>        name<span class="token punctuation">;</span>
    <span class="token comment">/** 老师主键 */</span>
    <span class="token annotation punctuation">@ExcelEntity</span><span class="token punctuation">(</span>id <span class="token operator">=</span> <span class="token string">"absent"</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token class-name">TeacherEntity</span> mathTeacher<span class="token punctuation">;</span>

    <span class="token annotation punctuation">@ExcelCollection</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">"学生"</span><span class="token punctuation">,</span> orderNum <span class="token operator">=</span> <span class="token string">"4"</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">StudentEntity</span><span class="token punctuation">&gt;</span></span> students<span class="token punctuation">;</span>
 <span class="token punctuation">}</span>
</pre><p>教师的实体</p>
<pre data-role="codeBlock" data-info="java" class="language-java"><span class="token annotation punctuation">@ExcelTarget</span><span class="token punctuation">(</span><span class="token string">"teacherEntity"</span><span class="token punctuation">)</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">TeacherEntity</span> <span class="token keyword">implements</span> java<span class="token punctuation">.</span>io<span class="token punctuation">.</span><span class="token class-name">Serializable</span> <span class="token punctuation">{</span>
    <span class="token keyword">private</span> <span class="token class-name">String</span> id<span class="token punctuation">;</span>
    <span class="token comment">/** name */</span>
    <span class="token annotation punctuation">@Excel</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">"主讲老师_major,代课老师_absent"</span><span class="token punctuation">,</span> orderNum <span class="token operator">=</span> <span class="token string">"1"</span><span class="token punctuation">,</span> isImportField <span class="token operator">=</span> <span class="token string">"true_major,true_absent"</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token class-name">String</span> name<span class="token punctuation">;</span>
</pre><p>这里在课程这个实体里面就完成了一堆多的导出,达到了我们基础需求,同时使用了orderNum对我们的列进行了排序,满足老师的需求,导出代码如下</p>
<pre data-role="codeBlock" data-info="java" class="language-java"> <span class="token class-name">Workbook</span> workbook <span class="token operator">=</span> <span class="token class-name">ExcelExportUtil</span><span class="token punctuation">.</span><span class="token function">exportExcel</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">ExportParams</span><span class="token punctuation">(</span><span class="token string">"2412312"</span><span class="token punctuation">,</span> <span class="token string">"测试"</span><span class="token punctuation">,</span> <span class="token string">"测试"</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
            <span class="token class-name">CourseEntity</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">,</span> list<span class="token punctuation">)</span><span class="token punctuation">;</span>
</pre><p>这样我们就完成了老师的需求,效果如图2.3.2-1<br>
但是课程名和代课老师没有合并,不太美观</p>
<p>路飞又果断给课程名称和代课老师加了needMerge = true的属性,就可以完成单元格的合并</p>
<pre data-role="codeBlock" data-info="java" class="language-java">   <span class="token comment">/** 课程名称 */</span>
    <span class="token annotation punctuation">@Excel</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">"课程名称"</span><span class="token punctuation">,</span> orderNum <span class="token operator">=</span> <span class="token string">"1"</span><span class="token punctuation">,</span> width <span class="token operator">=</span> <span class="token number">25</span><span class="token punctuation">,</span>needMerge <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token class-name">String</span>        name<span class="token punctuation">;</span>

   <span class="token comment">//--------------------------------</span>
   <span class="token comment">/** name */</span>
    <span class="token annotation punctuation">@Excel</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">"主讲老师_major,代课老师_absent"</span><span class="token punctuation">,</span> orderNum <span class="token operator">=</span> <span class="token string">"1"</span><span class="token punctuation">,</span>needMerge <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">,</span> isImportField <span class="token operator">=</span> <span class="token string">"true_major,true_absent"</span><span class="token punctuation">)</span>

</pre><p>效果如图2.3.2-2<br>
到这里,路飞就完美的完成了老师的任务,快乐的去交差了</p>
<p><img src="./easypoi_files/221100_MD8y_1157922.png" alt="图2.3.2-1"></p>
<p><img src="./easypoi_files/222202_217m_1157922.png" alt="图2.3.2-2"></p>
<h3 class="mume-header" id="90102" ebook-toc-level-3="" heading="2.3.3 &amp;#x56FE;&amp;#x7247;&amp;#x7684;&amp;#x5BFC;&amp;#x51FA;">2.3.3 图片的导出</h3>

<p>在日常运作中不可避免的会遇到图片的导入导出,这里提供了两种类型的图片导出方式</p>
<pre data-role="codeBlock" data-info="java" class="language-java"><span class="token annotation punctuation">@Excel</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">"公司LOGO"</span><span class="token punctuation">,</span> type <span class="token operator">=</span> <span class="token number">2</span> <span class="token punctuation">,</span>width <span class="token operator">=</span> <span class="token number">40</span> <span class="token punctuation">,</span> height <span class="token operator">=</span> <span class="token number">20</span><span class="token punctuation">,</span>imageType <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token class-name">String</span> companyLogo<span class="token punctuation">;</span>
</pre><ol>
<li>表示type =2 该字段类型为图片,imageType=1 (默认可以不填),表示从file读取,字段类型是个字符串类型<br>
可以用相对路径也可以用绝对路径,绝对路径优先依次获取</li>
</ol>
<pre data-role="codeBlock" data-info="java" class="language-java"><span class="token annotation punctuation">@Excel</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">"公司LOGO"</span><span class="token punctuation">,</span> type <span class="token operator">=</span> <span class="token number">2</span> <span class="token punctuation">,</span>width <span class="token operator">=</span> <span class="token number">40</span> <span class="token punctuation">,</span> height <span class="token operator">=</span> <span class="token number">20</span><span class="token punctuation">,</span>imageType <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token keyword">byte</span><span class="token punctuation">[</span><span class="token punctuation">]</span> companyLogo<span class="token punctuation">;</span>
</pre><p>2.表示type =2 该字段类型为图片,imageType=2 ,表示从数据库或者已经读取完毕,字段类型是个字节数组<br>
直接使用<br>
同时,image 类型的cell最好设置好宽和高,<strong>会百分百缩放到cell那么大,不是原尺寸,这里注意下</strong></p>
<p>效果如下</p>
<pre data-role="codeBlock" data-info="java" class="language-java"><span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">CompanyHasImgModel</span><span class="token punctuation">&gt;</span></span> list<span class="token punctuation">;</span>

    <span class="token annotation punctuation">@Before</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">initData</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        list <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ArrayList</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">CompanyHasImgModel</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        list<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">CompanyHasImgModel</span><span class="token punctuation">(</span><span class="token string">"百度"</span><span class="token punctuation">,</span> <span class="token string">"imgs/company/baidu.png"</span><span class="token punctuation">,</span> <span class="token string">"北京市海淀区西北旺东路10号院百度科技园1号楼"</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        list<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">CompanyHasImgModel</span><span class="token punctuation">(</span><span class="token string">"阿里巴巴"</span><span class="token punctuation">,</span> <span class="token string">"imgs/company/ali.png"</span><span class="token punctuation">,</span> <span class="token string">"北京市海淀区西北旺东路10号院百度科技园1号楼"</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        list<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">CompanyHasImgModel</span><span class="token punctuation">(</span><span class="token string">"Lemur"</span><span class="token punctuation">,</span> <span class="token string">"imgs/company/lemur.png"</span><span class="token punctuation">,</span> <span class="token string">"亚马逊热带雨林"</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        list<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">CompanyHasImgModel</span><span class="token punctuation">(</span><span class="token string">"一众"</span><span class="token punctuation">,</span> <span class="token string">"imgs/company/one.png"</span><span class="token punctuation">,</span> <span class="token string">"山东济宁俺家"</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>


    <span class="token punctuation">}</span>

    <span class="token annotation punctuation">@Test</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">exportCompanyImg</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">throws</span> <span class="token class-name">Exception</span> <span class="token punctuation">{</span>

        <span class="token class-name">File</span> savefile <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">File</span><span class="token punctuation">(</span><span class="token string">"D:/excel/"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>savefile<span class="token punctuation">.</span><span class="token function">exists</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            savefile<span class="token punctuation">.</span><span class="token function">mkdirs</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token class-name">Workbook</span> workbook <span class="token operator">=</span> <span class="token class-name">ExcelExportUtil</span><span class="token punctuation">.</span><span class="token function">exportExcel</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">ExportParams</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token class-name">CompanyHasImgModel</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">,</span> list<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">FileOutputStream</span> fos <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">FileOutputStream</span><span class="token punctuation">(</span><span class="token string">"D:/excel/ExcelExportHasImgTest.exportCompanyImg.xls"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        workbook<span class="token punctuation">.</span><span class="token function">write</span><span class="token punctuation">(</span>fos<span class="token punctuation">)</span><span class="token punctuation">;</span>
        fos<span class="token punctuation">.</span><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</pre><p>运行效果</p>
<p><img src="./easypoi_files/144432_tkYG_1157922.png" alt="2.3.3 -1"></p>
<h3 class="mume-header" id="90103" ebook-toc-level-3="" heading="2.3.4 Excel&amp;#x5BFC;&amp;#x5165;&amp;#x4ECB;&amp;#x7ECD;">2.3.4 Excel导入介绍</h3>

<p>有导出就有导入,基于注解的导入导出,配置配置上是一样的,只是方式反过来而已,比如类型的替换 导出的时候是1替换成男,2替换成女,导入的时候则反过来,男变成1 ,女变成2,时间也是类似<br>
导出的时候date被格式化成 2017-8-25 ,导入的时候2017-8-25被格式成date类型<br>
下面说下导入的基本代码,注解啥的都是上面讲过了,这里就不累赘了</p>
<pre data-role="codeBlock" data-info="java" class="language-java">  <span class="token annotation punctuation">@Test</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">test2</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token class-name">ImportParams</span> params <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ImportParams</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        params<span class="token punctuation">.</span><span class="token function">setTitleRows</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        params<span class="token punctuation">.</span><span class="token function">setHeadRows</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">long</span> start <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getTime</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">MsgClient</span><span class="token punctuation">&gt;</span></span> list <span class="token operator">=</span> <span class="token class-name">ExcelImportUtil</span><span class="token punctuation">.</span><span class="token function">importExcel</span><span class="token punctuation">(</span>
           <span class="token keyword">new</span> <span class="token class-name">File</span><span class="token punctuation">(</span><span class="token class-name">PoiPublicUtil</span><span class="token punctuation">.</span><span class="token function">getWebRootPath</span><span class="token punctuation">(</span><span class="token string">"import/ExcelExportMsgClient.xlsx"</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
            <span class="token class-name">MsgClient</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">,</span> params<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getTime</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">-</span> start<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>list<span class="token punctuation">.</span><span class="token function">size</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token class-name">ReflectionToStringBuilder</span><span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span>list<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</pre><p>基本是写法也很简单,ImportParams 参数介绍下</p>
<table>
<thead>
<tr>
<th>属性</th>
<th>类型</th>
<th>默认值</th>
<th>功能</th>
</tr>
</thead>
<tbody>
<tr>
<td>titleRows</td>
<td>int</td>
<td>0</td>
<td>表格标题行数,默认0</td>
</tr>
<tr>
<td>headRows</td>
<td>int</td>
<td>1</td>
<td>表头行数,默认1</td>
</tr>
<tr>
<td>startRows</td>
<td>int</td>
<td>0</td>
<td>字段真正值和列标题之间的距离 默认0</td>
</tr>
<tr>
<td>keyIndex</td>
<td>int</td>
<td>0</td>
<td>主键设置,如何这个cell没有值,就跳过 或者认为这个是list的下面的值,这一列必须有值,不然认为这列为无效数据</td>
</tr>
<tr>
<td>startSheetIndex</td>
<td>int</td>
<td>0</td>
<td>开始读取的sheet位置,默认为0</td>
</tr>
<tr>
<td>sheetNum</td>
<td>int</td>
<td>1</td>
<td>上传表格需要读取的sheet 数量,默认为1</td>
</tr>
<tr>
<td>needSave</td>
<td>boolean</td>
<td>false</td>
<td>是否需要保存上传的Excel</td>
</tr>
<tr>
<td>needVerfiy</td>
<td>boolean</td>
<td>false</td>
<td>是否需要校验上传的Excel</td>
</tr>
<tr>
<td>saveUrl</td>
<td>String</td>
<td>"upload/excelUpload"</td>
<td>保存上传的Excel目录,默认是 如 TestEntity这个类保存路径就是upload/excelUpload/Test/yyyyMMddHHmss_ 保存名称上传时间_五位随机数</td>
</tr>
<tr>
<td>verifyHanlder</td>
<td>IExcelVerifyHandler</td>
<td>null</td>
<td>校验处理接口,自定义校验</td>
</tr>
<tr>
<td>lastOfInvalidRow</td>
<td>int</td>
<td>0</td>
<td>最后的无效行数,不读的行数</td>
</tr>
<tr>
<td>readRows</td>
<td>int</td>
<td>0</td>
<td>手动控制读取的行数</td>
</tr>
<tr>
<td>importFields</td>
<td>String[]</td>
<td>null</td>
<td>导入时校验数据模板,是不是正确的Excel</td>
</tr>
<tr>
<td>keyMark</td>
<td>String</td>
<td>":"</td>
<td>Key-Value 读取标记,以这个为Key,后面一个Cell 为Value,多个改为ArrayList</td>
</tr>
<tr>
<td>readSingleCell</td>
<td>boolean</td>
<td>false</td>
<td>按照Key-Value 规则读取全局扫描Excel,但是跳过List读取范围提升性能,仅仅支持titleRows + headRows + startRows 以及 lastOfInvalidRow</td>
</tr>
<tr>
<td>dataHanlder</td>
<td>IExcelDataHandler</td>
<td>null</td>
<td>数据处理接口,以此为主,replace,format都在这后面</td>
</tr>
</tbody>
</table>
<h3 class="mume-header" id="90104" ebook-toc-level-3="" heading="2.3.5 Excel&amp;#x5BFC;&amp;#x5165;&amp;#x5C0F;&amp;#x529F;&amp;#x80FD;">2.3.5 Excel导入小功能</h3>

<ol>
<li>
<p>读取指定的sheet<br>
比如要读取上传得第二个sheet 那么需要把startSheetIndex = 1 就可以了</p>
</li>
<li>
<p>读取几个sheet<br>
比如读取前2个sheet,那么 sheetNum=2 就可以了</p>
</li>
<li>
<p>读取第二个到第五个sheet<br>
设置 startSheetIndex = 1 然后sheetNum = 4</p>
</li>
<li>
<p>读取全部的sheet<br>
sheetNum  设置大点就可以了</p>
</li>
<li>
<p>保存Excel<br>
设置 needVerfiy = true,默认保存的路径为upload/excelUpload/Test/yyyyMMddHHmss_***** 保存名称上传时间_五位随机数<br>
如果自定义路径 修改下saveUrl 就可以了,同时saveUrl也是图片上传时候的保存的路径</p>
</li>
<li>
<p>判断一个Excel是不是合法的Excel<br>
importFields 设置下值,就是表示表头必须至少包含的字段,如果缺一个就是不合法的excel,不导入</p>
</li>
</ol>
<h3 class="mume-header" id="90105" ebook-toc-level-3="" heading="2.3.6 &amp;#x56FE;&amp;#x7247;&amp;#x7684;&amp;#x5BFC;&amp;#x5165;">2.3.6 图片的导入</h3>

<p>有图片的导出就有图片的导入,导入的配置和导出是一样的,但是需要设置保存路径<br>
1.设置保存路径saveUrl 默认为"upload/excelUpload"<br>
可以手动修改 ImportParams 修改下就可以了</p>
<pre data-role="codeBlock" data-info="java" class="language-java"> <span class="token annotation punctuation">@Test</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">test</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">try</span> <span class="token punctuation">{</span>
            <span class="token class-name">ImportParams</span> params <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ImportParams</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            params<span class="token punctuation">.</span><span class="token function">setNeedSave</span><span class="token punctuation">(</span><span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">CompanyHasImgModel</span><span class="token punctuation">&gt;</span></span> result <span class="token operator">=</span> <span class="token class-name">ExcelImportUtil</span><span class="token punctuation">.</span><span class="token function">importExcel</span><span class="token punctuation">(</span>
                    <span class="token keyword">new</span> <span class="token class-name">File</span><span class="token punctuation">(</span><span class="token class-name">PoiPublicUtil</span><span class="token punctuation">.</span><span class="token function">getWebRootPath</span><span class="token punctuation">(</span><span class="token string">"import/imgexcel.xls"</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                    <span class="token class-name">CompanyHasImgModel</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">,</span> params<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> result<span class="token punctuation">.</span><span class="token function">size</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token class-name">ReflectionToStringBuilder</span><span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span>result<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span>i<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
            <span class="token class-name">Assert</span><span class="token punctuation">.</span><span class="token function">assertTrue</span><span class="token punctuation">(</span>result<span class="token punctuation">.</span><span class="token function">size</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">==</span> <span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">Exception</span> e<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            e<span class="token punctuation">.</span><span class="token function">printStackTrace</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</pre><p>导入日志</p>
<pre data-role="codeBlock" data-info="java" class="language-java"><span class="token number">16</span><span class="token operator">:</span><span class="token number">35</span><span class="token operator">:</span><span class="token number">43.081</span> <span class="token punctuation">[</span>main<span class="token punctuation">]</span> DEBUG c<span class="token punctuation">.</span>a<span class="token punctuation">.</span>e<span class="token punctuation">.</span>e<span class="token punctuation">.</span>imports<span class="token punctuation">.</span><span class="token class-name">ExcelImportServer</span> <span class="token operator">-</span> <span class="token class-name">Excel</span> <span class="token keyword">import</span> start <span class="token punctuation">,</span><span class="token keyword">class</span> is <span class="token keyword">class</span> cn<span class="token punctuation">.</span>afterturn<span class="token punctuation">.</span>easypoi<span class="token punctuation">.</span>test<span class="token punctuation">.</span>entity<span class="token punctuation">.</span>img<span class="token punctuation">.</span><span class="token class-name">CompanyHasImgModel</span>
<span class="token number">16</span><span class="token operator">:</span><span class="token number">35</span><span class="token operator">:</span><span class="token number">43.323</span> <span class="token punctuation">[</span>main<span class="token punctuation">]</span> DEBUG c<span class="token punctuation">.</span>a<span class="token punctuation">.</span>e<span class="token punctuation">.</span>e<span class="token punctuation">.</span>imports<span class="token punctuation">.</span><span class="token class-name">ExcelImportServer</span> <span class="token operator">-</span>  start <span class="token keyword">to</span> read excel by is <span class="token punctuation">,</span>startTime is <span class="token number">1503650143323</span>
<span class="token number">16</span><span class="token operator">:</span><span class="token number">35</span><span class="token operator">:</span><span class="token number">43.344</span> <span class="token punctuation">[</span>main<span class="token punctuation">]</span> DEBUG c<span class="token punctuation">.</span>a<span class="token punctuation">.</span>e<span class="token punctuation">.</span>e<span class="token punctuation">.</span>imports<span class="token punctuation">.</span><span class="token class-name">ExcelImportServer</span> <span class="token operator">-</span>  end <span class="token keyword">to</span> read excel by is <span class="token punctuation">,</span>endTime is <span class="token number">1503650143344</span>
<span class="token number">16</span><span class="token operator">:</span><span class="token number">35</span><span class="token operator">:</span><span class="token number">43.429</span> <span class="token punctuation">[</span>main<span class="token punctuation">]</span> DEBUG c<span class="token punctuation">.</span>a<span class="token punctuation">.</span>e<span class="token punctuation">.</span>e<span class="token punctuation">.</span>imports<span class="token punctuation">.</span><span class="token class-name">ExcelImportServer</span> <span class="token operator">-</span>  end <span class="token keyword">to</span> read excel list by pos <span class="token punctuation">,</span>endTime is <span class="token number">1503650143429</span>
cn<span class="token punctuation">.</span>afterturn<span class="token punctuation">.</span>easypoi<span class="token punctuation">.</span>test<span class="token punctuation">.</span>entity<span class="token punctuation">.</span>img<span class="token punctuation">.</span><span class="token class-name">CompanyHasImgModel</span><span class="token annotation punctuation">@1b083826</span><span class="token punctuation">[</span>companyName<span class="token operator">=</span>百度<span class="token punctuation">,</span>companyLogo<span class="token operator">=</span>upload<span class="token operator">/</span><span class="token class-name">CompanyHasImgModel</span><span class="token operator">/</span>pic88273295062<span class="token punctuation">.</span>PNG<span class="token punctuation">,</span>companyAddr<span class="token operator">=</span>北京市海淀区西北旺东路<span class="token number">10</span>号院百度科技园<span class="token number">1</span>号楼<span class="token punctuation">]</span>
cn<span class="token punctuation">.</span>afterturn<span class="token punctuation">.</span>easypoi<span class="token punctuation">.</span>test<span class="token punctuation">.</span>entity<span class="token punctuation">.</span>img<span class="token punctuation">.</span><span class="token class-name">CompanyHasImgModel</span><span class="token annotation punctuation">@105fece7</span><span class="token punctuation">[</span>companyName<span class="token operator">=</span>阿里巴巴<span class="token punctuation">,</span>companyLogo<span class="token operator">=</span>upload<span class="token operator">/</span><span class="token class-name">CompanyHasImgModel</span><span class="token operator">/</span>pic22507938183<span class="token punctuation">.</span>PNG<span class="token punctuation">,</span>companyAddr<span class="token operator">=</span>北京市海淀区西北旺东路<span class="token number">10</span>号院百度科技园<span class="token number">1</span>号楼<span class="token punctuation">]</span>
cn<span class="token punctuation">.</span>afterturn<span class="token punctuation">.</span>easypoi<span class="token punctuation">.</span>test<span class="token punctuation">.</span>entity<span class="token punctuation">.</span>img<span class="token punctuation">.</span><span class="token class-name">CompanyHasImgModel</span><span class="token annotation punctuation">@3ec300f1</span><span class="token punctuation">[</span>companyName<span class="token operator">=</span><span class="token class-name">Lemur</span><span class="token punctuation">,</span>companyLogo<span class="token operator">=</span>upload<span class="token operator">/</span><span class="token class-name">CompanyHasImgModel</span><span class="token operator">/</span>pic86390457892<span class="token punctuation">.</span>PNG<span class="token punctuation">,</span>companyAddr<span class="token operator">=</span>亚马逊热带雨林<span class="token punctuation">]</span>
cn<span class="token punctuation">.</span>afterturn<span class="token punctuation">.</span>easypoi<span class="token punctuation">.</span>test<span class="token punctuation">.</span>entity<span class="token punctuation">.</span>img<span class="token punctuation">.</span><span class="token class-name">CompanyHasImgModel</span><span class="token annotation punctuation">@482cd91f</span><span class="token punctuation">[</span>companyName<span class="token operator">=</span>一众<span class="token punctuation">,</span>companyLogo<span class="token operator">=</span>upload<span class="token operator">/</span><span class="token class-name">CompanyHasImgModel</span><span class="token operator">/</span>pic69566571093<span class="token punctuation">.</span>PNG<span class="token punctuation">,</span>companyAddr<span class="token operator">=</span>山东济宁俺家<span class="token punctuation">]</span>
</pre><p><img src="./easypoi_files/163643_LlQg_1157922.png" alt="2.3.5-1"></p>
<h3 class="mume-header" id="90106" ebook-toc-level-3="" heading="2.3.7 Excel&amp;#x591A;Sheet&amp;#x5BFC;&amp;#x51FA;">2.3.7 Excel多Sheet导出</h3>

<p>目前单Sheet和单Class的方式比较多，对于多Sheet的方式还是一片空白，这里做一下说明：</p>
<p>导出基本采用ExportParams 这个对象，进行参数配置；<br>
我们需要进行多Sheet导出，那么就需要定义一个基础配置对象</p>
<pre data-role="codeBlock" data-info="java" class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">ExportView</span> <span class="token punctuation">{</span>
	
	<span class="token keyword">public</span> <span class="token class-name">ExportView</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
		
	<span class="token punctuation">}</span>
	
	
	<span class="token keyword">private</span> <span class="token class-name">ExportParams</span> exportParams<span class="token punctuation">;</span>
	<span class="token keyword">private</span> <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span><span class="token punctuation">&gt;</span></span> dataList<span class="token punctuation">;</span>
	<span class="token keyword">private</span> <span class="token class-name">Class</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span><span class="token punctuation">&gt;</span></span> cls<span class="token punctuation">;</span>
	
	<span class="token keyword">public</span> <span class="token class-name">ExportParams</span> <span class="token function">getExportParams</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">return</span> exportParams<span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
	<span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">setExportParams</span><span class="token punctuation">(</span><span class="token class-name">ExportParams</span> exportParams<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">this</span><span class="token punctuation">.</span>exportParams <span class="token operator">=</span> exportParams<span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
	
	<span class="token keyword">public</span> <span class="token class-name">Class</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span><span class="token punctuation">&gt;</span></span> <span class="token function">getCls</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">return</span> cls<span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
	<span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">setCls</span><span class="token punctuation">(</span><span class="token class-name">Class</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span><span class="token punctuation">&gt;</span></span> cls<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">this</span><span class="token punctuation">.</span>cls <span class="token operator">=</span> cls<span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
	<span class="token keyword">public</span> <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span><span class="token punctuation">&gt;</span></span> <span class="token function">getDataList</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">return</span> dataList<span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
	<span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">setDataList</span><span class="token punctuation">(</span><span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span><span class="token punctuation">&gt;</span></span> dataList<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">this</span><span class="token punctuation">.</span>dataList <span class="token operator">=</span> dataList<span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
	
	
	<span class="token keyword">public</span> <span class="token class-name">ExportView</span><span class="token punctuation">(</span><span class="token class-name">Builder</span> builder<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">this</span><span class="token punctuation">.</span>exportParams <span class="token operator">=</span> builder<span class="token punctuation">.</span>exportParams<span class="token punctuation">;</span>
		<span class="token keyword">this</span><span class="token punctuation">.</span>dataList <span class="token operator">=</span> builder<span class="token punctuation">.</span>dataList<span class="token punctuation">;</span>
		<span class="token keyword">this</span><span class="token punctuation">.</span>cls <span class="token operator">=</span> builder<span class="token punctuation">.</span>cls<span class="token punctuation">;</span>
	<span class="token punctuation">}</span>

	<span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">class</span> <span class="token class-name">Builder</span> <span class="token punctuation">{</span>
		<span class="token keyword">private</span> <span class="token class-name">ExportParams</span> exportParams<span class="token operator">=</span><span class="token keyword">null</span><span class="token punctuation">;</span>
		<span class="token keyword">private</span> <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span><span class="token punctuation">&gt;</span></span> dataList<span class="token operator">=</span><span class="token keyword">null</span><span class="token punctuation">;</span>
		<span class="token keyword">private</span> <span class="token class-name">Class</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span><span class="token punctuation">&gt;</span></span> cls<span class="token operator">=</span><span class="token keyword">null</span><span class="token punctuation">;</span>

		<span class="token keyword">public</span> <span class="token class-name">Builder</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>

		<span class="token punctuation">}</span>
		<span class="token keyword">public</span> <span class="token class-name">Builder</span> <span class="token function">exportParams</span><span class="token punctuation">(</span><span class="token class-name">ExportParams</span> exportParams<span class="token punctuation">)</span> <span class="token punctuation">{</span>
			<span class="token keyword">this</span><span class="token punctuation">.</span>exportParams <span class="token operator">=</span> exportParams<span class="token punctuation">;</span>
			<span class="token keyword">return</span> <span class="token keyword">this</span><span class="token punctuation">;</span>
		<span class="token punctuation">}</span>

		<span class="token keyword">public</span> <span class="token class-name">Builder</span> <span class="token function">dataList</span><span class="token punctuation">(</span><span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span><span class="token punctuation">&gt;</span></span> dataList<span class="token punctuation">)</span> <span class="token punctuation">{</span>
			<span class="token keyword">this</span><span class="token punctuation">.</span>dataList <span class="token operator">=</span> dataList<span class="token punctuation">;</span>
			<span class="token keyword">return</span> <span class="token keyword">this</span><span class="token punctuation">;</span>
		<span class="token punctuation">}</span>
		<span class="token keyword">public</span> <span class="token class-name">Builder</span> <span class="token function">cls</span><span class="token punctuation">(</span><span class="token class-name">Class</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span><span class="token punctuation">&gt;</span></span> cls<span class="token punctuation">)</span> <span class="token punctuation">{</span>
			<span class="token keyword">this</span><span class="token punctuation">.</span>cls <span class="token operator">=</span> cls<span class="token punctuation">;</span>
			<span class="token keyword">return</span> <span class="token keyword">this</span><span class="token punctuation">;</span>
		<span class="token punctuation">}</span>

		<span class="token keyword">public</span> <span class="token class-name">ExportView</span> <span class="token function">create</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
			<span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">ExportView</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token punctuation">}</span>
	<span class="token punctuation">}</span>
	
	
<span class="token punctuation">}</span>
</pre><p>对象主要有三个属性：<br>
// 该注解配置的导出属性</p>
<ol>
<li>ExportParams exportParams<br>
// 对应注解 class 实例对象的数据集合</li>
<li>List&lt;?&gt; dataList<br>
// 对应注解的 class</li>
<li>Class&lt;?&gt; cls</li>
</ol>
<p>这里没有用泛型，因为多Sheet导出时，会引用到不同的注解对象；</p>
<p>定义基础配置的集合</p>
<pre data-role="codeBlock" data-info="java" class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">ExportMoreView</span> <span class="token punctuation">{</span>
	<span class="token keyword">private</span> <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">ExportView</span><span class="token punctuation">&gt;</span></span> moreViewList<span class="token operator">=</span><span class="token class-name">Lists</span><span class="token punctuation">.</span><span class="token function">newArrayList</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

	<span class="token keyword">public</span> <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">ExportView</span><span class="token punctuation">&gt;</span></span> <span class="token function">getMoreViewList</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">return</span> moreViewList<span class="token punctuation">;</span>
	<span class="token punctuation">}</span>

	<span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">setMoreViewList</span><span class="token punctuation">(</span><span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">ExportView</span><span class="token punctuation">&gt;</span></span> moreViewList<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">this</span><span class="token punctuation">.</span>moreViewList <span class="token operator">=</span> moreViewList<span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</pre><p>最后在实现调用的方法中，对整个集合进行配置和解析</p>
<pre data-role="codeBlock" data-info="java" class="language-java"><span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Map</span><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span><span class="token punctuation">&gt;</span></span> exportParamList<span class="token operator">=</span><span class="token class-name">Lists</span><span class="token punctuation">.</span><span class="token function">newArrayList</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token comment">//该行主要用于获取业务数据，请根据具体的情况进行修改和调整	</span>
<span class="token class-name">ExportMoreView</span> moreView<span class="token operator">=</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">getBaseTransferService</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">mergeExportView</span><span class="token punctuation">(</span>templateTypeCode<span class="token punctuation">)</span><span class="token punctuation">;</span>
         <span class="token comment">//迭代导出对象，将对应的配置信息写入到实际的配置中</span>
		<span class="token keyword">for</span><span class="token punctuation">(</span><span class="token class-name">ExportView</span> view<span class="token operator">:</span>moreView<span class="token punctuation">.</span><span class="token function">getMoreViewList</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
			<span class="token class-name">Map</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span></span> valueMap<span class="token operator">=</span><span class="token class-name">Maps</span><span class="token punctuation">.</span><span class="token function">newHashMap</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
			valueMap<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token class-name">NormalExcelConstants</span><span class="token punctuation">.</span>PARAMS<span class="token punctuation">,</span>view<span class="token punctuation">.</span><span class="token function">getExportParams</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
			valueMap<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token class-name">NormalExcelConstants</span><span class="token punctuation">.</span>DATA_LIST<span class="token punctuation">,</span>view<span class="token punctuation">.</span><span class="token function">getDataList</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
			valueMap<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token class-name">NormalExcelConstants</span><span class="token punctuation">.</span>CLASS<span class="token punctuation">,</span>view<span class="token punctuation">.</span><span class="token function">getCls</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
			exportParamList<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>valueMap<span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token punctuation">}</span>
      <span class="token comment">//实现导出配置</span>
		modelMap<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token class-name">NormalExcelConstants</span><span class="token punctuation">.</span>FILE_NAME<span class="token punctuation">,</span><span class="token keyword">new</span> <span class="token class-name">DateTime</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span><span class="token string">"yyyyMMddHHmmss"</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
     <span class="token comment">//将转换完成的配置接入到导出中</span>
		modelMap<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token class-name">NormalExcelConstants</span><span class="token punctuation">.</span>MAP_LIST<span class="token punctuation">,</span>exportParamList<span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token keyword">return</span> <span class="token class-name">NormalExcelConstants</span><span class="token punctuation">.</span>JEECG_EXCEL_VIEW<span class="token punctuation">;</span>


</pre><p>如果不是采用的MVC的方式，请将转换的配置采用以下的方式实现：</p>
<p><img src="./easypoi_files/111045_9s7X_2343396.png" alt="参见ExcelExportUtil"></p>
<h2 class="mume-header" id="302" ebook-toc-level-2="" heading="2.4 &amp;#x6CE8;&amp;#x89E3;&amp;#x53D8;&amp;#x79CD;-&amp;#x66F4;&amp;#x81EA;&amp;#x7531;&amp;#x7684;&amp;#x5BFC;&amp;#x51FA;">2.4 注解变种-更自由的导出</h2>

<p>这天老师又把路飞喊道的办公室,要求路飞导出班级学生的整体信息</p>
<pre data-role="codeBlock" data-info="java" class="language-java">    <span class="token annotation punctuation">@Excel</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">"学生姓名"</span><span class="token punctuation">,</span> height <span class="token operator">=</span> <span class="token number">20</span><span class="token punctuation">,</span> width <span class="token operator">=</span> <span class="token number">30</span><span class="token punctuation">,</span> isImportField <span class="token operator">=</span> <span class="token string">"true_st"</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token class-name">String</span>        name<span class="token punctuation">;</span>
    <span class="token annotation punctuation">@Excel</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">"学生性别"</span><span class="token punctuation">,</span> replace <span class="token operator">=</span> <span class="token punctuation">{</span> <span class="token string">"男_1"</span><span class="token punctuation">,</span> <span class="token string">"女_2"</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> suffix <span class="token operator">=</span> <span class="token string">"生"</span><span class="token punctuation">,</span> isImportField <span class="token operator">=</span> <span class="token string">"true_st"</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token keyword">int</span>           sex<span class="token punctuation">;</span>
    <span class="token annotation punctuation">@Excel</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">"出生日期"</span><span class="token punctuation">,</span> databaseFormat <span class="token operator">=</span> <span class="token string">"yyyyMMddHHmmss"</span><span class="token punctuation">,</span> format <span class="token operator">=</span> <span class="token string">"yyyy-MM-dd"</span><span class="token punctuation">,</span> isImportField <span class="token operator">=</span> <span class="token string">"true_st"</span><span class="token punctuation">,</span> width <span class="token operator">=</span> <span class="token number">20</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token class-name">Date</span>          birthday<span class="token punctuation">;</span>
    <span class="token annotation punctuation">@Excel</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">"进校日期"</span><span class="token punctuation">,</span> databaseFormat <span class="token operator">=</span> <span class="token string">"yyyyMMddHHmmss"</span><span class="token punctuation">,</span> format <span class="token operator">=</span> <span class="token string">"yyyy-MM-dd"</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token class-name">Date</span> registrationDate<span class="token punctuation">;</span>
</pre><p>路飞飞快的用到上面的学到的知识搞定了,这这时有一个老师把路飞叫去,说想要导出一个不要出生日期的Excel,感觉用户需求很无奈,路飞又造两个一个bean,把这个注解去掉了,来导出</p>
<pre data-role="codeBlock" data-info="java" class="language-java">    <span class="token annotation punctuation">@Excel</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">"学生姓名"</span><span class="token punctuation">,</span> height <span class="token operator">=</span> <span class="token number">20</span><span class="token punctuation">,</span> width <span class="token operator">=</span> <span class="token number">30</span><span class="token punctuation">,</span> isImportField <span class="token operator">=</span> <span class="token string">"true_st"</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token class-name">String</span>        name<span class="token punctuation">;</span>
    <span class="token annotation punctuation">@Excel</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">"学生性别"</span><span class="token punctuation">,</span> replace <span class="token operator">=</span> <span class="token punctuation">{</span> <span class="token string">"男_1"</span><span class="token punctuation">,</span> <span class="token string">"女_2"</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> suffix <span class="token operator">=</span> <span class="token string">"生"</span><span class="token punctuation">,</span> isImportField <span class="token operator">=</span> <span class="token string">"true_st"</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token keyword">int</span>           sex<span class="token punctuation">;</span>
    <span class="token annotation punctuation">@Excel</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">"进校日期"</span><span class="token punctuation">,</span> databaseFormat <span class="token operator">=</span> <span class="token string">"yyyyMMddHHmmss"</span><span class="token punctuation">,</span> format <span class="token operator">=</span> <span class="token string">"yyyy-MM-dd"</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token class-name">Date</span> registrationDate<span class="token punctuation">;</span>
</pre><p>虽然解决了老师的需求,但这个并不是一个完美的解决方案,下面介绍一个更自由的解决方案</p>
<p>注解的导出,规定我们必须把model写好,并且注解写好,每次导出的Excel都是固定的,无法动态控制导出的列,虽然可以通过id来处理一个案例,但是自由度远远不够,这里介绍个变种支持,基本支持注解所有的功能</p>
<p>基于List<excelexportentity> 的导出,ExcelExportEntity是注解经过处理翻译成的实体类,两者几乎是一对的,所以如果我们要动态自定义导出列,我们只要动态拼装ExcelExportEntity就可以了<br>
下面我们看下这个类</excelexportentity></p>
<pre data-role="codeBlock" data-info="java" class="language-java"><span class="token comment">/**
     * 如果是MAP导出,这个是map的key
     */</span>
    <span class="token keyword">private</span> <span class="token class-name">Object</span>                  key<span class="token punctuation">;</span>

    <span class="token keyword">private</span> <span class="token keyword">double</span>                  width           <span class="token operator">=</span> <span class="token number">10</span><span class="token punctuation">;</span>

    <span class="token keyword">private</span> <span class="token keyword">double</span>                  height          <span class="token operator">=</span> <span class="token number">10</span><span class="token punctuation">;</span>

    <span class="token comment">/**
     * 图片的类型,1是文件,2是数据库
     */</span>
    <span class="token keyword">private</span> <span class="token keyword">int</span>                     exportImageType <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>

    <span class="token comment">/**
     * 排序顺序
     */</span>
    <span class="token keyword">private</span> <span class="token keyword">int</span>                     orderNum        <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>

    <span class="token comment">/**
     * 是否支持换行
     */</span>
    <span class="token keyword">private</span> <span class="token keyword">boolean</span>                 isWrap<span class="token punctuation">;</span>

    <span class="token comment">/**
     * 是否需要合并
     */</span>
    <span class="token keyword">private</span> <span class="token keyword">boolean</span>                 needMerge<span class="token punctuation">;</span>
    <span class="token comment">/**
     * 单元格纵向合并
     */</span>
    <span class="token keyword">private</span> <span class="token keyword">boolean</span>                 mergeVertical<span class="token punctuation">;</span>
    <span class="token comment">/**
     * 合并依赖
     */</span>
    <span class="token keyword">private</span> <span class="token keyword">int</span><span class="token punctuation">[</span><span class="token punctuation">]</span>                   mergeRely<span class="token punctuation">;</span>
    <span class="token comment">/**
     * 后缀
     */</span>
    <span class="token keyword">private</span> <span class="token class-name">String</span>                  suffix<span class="token punctuation">;</span>
    <span class="token comment">/**
     * 统计
     */</span>
    <span class="token keyword">private</span> <span class="token keyword">boolean</span>                 isStatistics<span class="token punctuation">;</span>

    <span class="token keyword">private</span> <span class="token class-name">String</span>                   numFormat<span class="token punctuation">;</span>

    <span class="token keyword">private</span> <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">ExcelExportEntity</span><span class="token punctuation">&gt;</span></span> list<span class="token punctuation">;</span>
</pre><p>基本上是和注解对应的, <strong>List<excelexportentity> list 这个是对应的一对多的导出,相当于集合,其他基本上都是和注解保持一致</excelexportentity></strong><br>
下面给出正常的demo</p>
<pre data-role="codeBlock" data-info="java" class="language-java"><span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">test</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">try</span> <span class="token punctuation">{</span>
            <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">ExcelExportEntity</span><span class="token punctuation">&gt;</span></span> entity <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ArrayList</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">ExcelExportEntity</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">//构造对象等同于@Excel</span>
            <span class="token class-name">ExcelExportEntity</span> excelentity <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ExcelExportEntity</span><span class="token punctuation">(</span><span class="token string">"姓名"</span><span class="token punctuation">,</span> <span class="token string">"name"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            excelentity<span class="token punctuation">.</span><span class="token function">setNeedMerge</span><span class="token punctuation">(</span><span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            entity<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>excelentity<span class="token punctuation">)</span><span class="token punctuation">;</span>
            entity<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">ExcelExportEntity</span><span class="token punctuation">(</span><span class="token string">"性别"</span><span class="token punctuation">,</span> <span class="token string">"sex"</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            excelentity <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ExcelExportEntity</span><span class="token punctuation">(</span><span class="token keyword">null</span><span class="token punctuation">,</span> <span class="token string">"students"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">ExcelExportEntity</span><span class="token punctuation">&gt;</span></span> temp <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ArrayList</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">ExcelExportEntity</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            temp<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">ExcelExportEntity</span><span class="token punctuation">(</span><span class="token string">"姓名"</span><span class="token punctuation">,</span> <span class="token string">"name"</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            temp<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">ExcelExportEntity</span><span class="token punctuation">(</span><span class="token string">"性别"</span><span class="token punctuation">,</span> <span class="token string">"sex"</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">//构造List等同于@ExcelCollection </span>
            excelentity<span class="token punctuation">.</span><span class="token function">setList</span><span class="token punctuation">(</span>temp<span class="token punctuation">)</span><span class="token punctuation">;</span>
            entity<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>excelentity<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Map</span><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span><span class="token punctuation">&gt;</span></span> list <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ArrayList</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Map</span><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">//把我们构造好的bean对象放到params就可以了</span>
            <span class="token class-name">Workbook</span> workbook <span class="token operator">=</span> <span class="token class-name">ExcelExportUtil</span><span class="token punctuation">.</span><span class="token function">exportExcel</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">ExportParams</span><span class="token punctuation">(</span><span class="token string">"测试"</span><span class="token punctuation">,</span> <span class="token string">"测试"</span><span class="token punctuation">)</span><span class="token punctuation">,</span> entity<span class="token punctuation">,</span>
                list<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token class-name">FileOutputStream</span> fos <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">FileOutputStream</span><span class="token punctuation">(</span><span class="token string">"D:/excel/ExcelExportForMap.tt.xls"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            workbook<span class="token punctuation">.</span><span class="token function">write</span><span class="token punctuation">(</span>fos<span class="token punctuation">)</span><span class="token punctuation">;</span>
            fos<span class="token punctuation">.</span><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">FileNotFoundException</span> e<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            e<span class="token punctuation">.</span><span class="token function">printStackTrace</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">IOException</span> e<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            e<span class="token punctuation">.</span><span class="token function">printStackTrace</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
</pre><p>路飞想到了这个方案,并且用上面做了测试可以完美解决所以他把之前的代码改为了(<strong>代码有删减,基本上都是和注解对应的</strong>)</p>
<pre data-role="codeBlock" data-info="java" class="language-java"><span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">ExcelExportEntity</span><span class="token punctuation">&gt;</span></span> beanList <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ArrayList</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">ExcelExportEntity</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
beanList <span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">ExcelExportEntity</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">ExcelExportEntity</span><span class="token punctuation">(</span><span class="token string">"学生姓名"</span><span class="token punctuation">,</span> <span class="token string">"name"</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
beanList <span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">ExcelExportEntity</span><span class="token punctuation">(</span><span class="token string">"学生性别"</span><span class="token punctuation">,</span> <span class="token string">"sex"</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
beanList <span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">ExcelExportEntity</span><span class="token punctuation">(</span><span class="token string">"进校日期"</span><span class="token punctuation">,</span> <span class="token string">"registrationDate"</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">if</span><span class="token punctuation">(</span><span class="token function">needBirthday</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
  beanList <span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">ExcelExportEntity</span><span class="token punctuation">(</span><span class="token string">"出生日期"</span><span class="token punctuation">,</span> <span class="token string">"birthday"</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
  <span class="token class-name">Workbook</span> workbook <span class="token operator">=</span> <span class="token class-name">ExcelExportUtil</span><span class="token punctuation">.</span><span class="token function">exportExcel</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">ExportParams</span><span class="token punctuation">(</span><span class="token string">"测试"</span><span class="token punctuation">,</span> <span class="token string">"测试"</span><span class="token punctuation">)</span><span class="token punctuation">,</span> beanList <span class="token punctuation">,</span>
                list<span class="token punctuation">)</span><span class="token punctuation">;</span>
</pre><p>用同一套代买完美了支持了老师的需求,心满意足的回宿舍了^^</p>
<h2 class="mume-header" id="303" ebook-toc-level-2="" heading="2.5 Map&amp;#x5BFC;&amp;#x5165;,&amp;#x81EA;&amp;#x7531;&amp;#x53D1;&amp;#x6325;">2.5 Map导入,自由发挥</h2>

<p>这天,老师把路飞叫到办公室,总是被叫,能者的悲哀啊,让他临时导入一批数据,到数据库,但是中间需要处理一些字段逻辑没办法直接导入到数据库,<br>
这时路飞首先想到构造一个bean然后标记注解,导入处理对象,但是想想一次的对象太过于浪费,不如用map试试,获取map处理map也是一样的<br>
导入的逻辑就变成了</p>
<pre data-role="codeBlock" data-info="java" class="language-java">        <span class="token class-name">ImportParams</span> params <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ImportParams</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        params<span class="token punctuation">.</span><span class="token function">setDataHanlder</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">MapImportHanlder</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">long</span> start <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getTime</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Map</span><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span><span class="token punctuation">&gt;</span></span> list <span class="token operator">=</span> <span class="token class-name">ExcelImportUtil</span><span class="token punctuation">.</span><span class="token function">importExcel</span><span class="token punctuation">(</span>
            <span class="token keyword">new</span> <span class="token class-name">File</span><span class="token punctuation">(</span><span class="token class-name">PoiPublicUtil</span><span class="token punctuation">.</span><span class="token function">getWebRootPath</span><span class="token punctuation">(</span><span class="token string">"import/check.xls"</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token class-name">Map</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">,</span> params<span class="token punctuation">)</span><span class="token punctuation">;</span>
</pre><p>导入后,处理每个map,然后入库完美的解决了老师的需求,简单更快捷,和bean导入基础没有区别,省去了bean的构造时间</p>
<p><strong>PS:这个作者也只是在临时方案中或者一次性活当中使用,一般还是推荐注解这种方式,拥有更高的代码阅读性</strong><br>
!!!测试了时间的,最好导入使用文本格式,可以获取时间格式可能无法获取</p>
<h2 class="mume-header" id="304" ebook-toc-level-2="" heading="2.6 Excel&amp;#x7684;&amp;#x6837;&amp;#x5F0F;&amp;#x81EA;&amp;#x5B9A;&amp;#x4E49;">2.6 Excel的样式自定义</h2>

<p>"路飞,来办公室一趟",就这样路飞又被叫到了办公室,这次老师的需求是,想要一个漂亮点的Excel,希望路飞可以点缀下Excel,思来想去还是需要用poi的style来解决,但是如果每个都写style是不是太麻烦,而且Excel的styler数量是有限制的,这里就需要尽量复用已经创造的style,看看之前的Excel表格,大体上可以分为[标题,表头,表体],那可以说的就是创建一个接口每次调用这三个接口就可以了不说干就干</p>
<pre data-role="codeBlock" data-info="java" class="language-java"><span class="token keyword">public</span> <span class="token keyword">interface</span> <span class="token class-name">IExcelExportStyler</span> <span class="token punctuation">{</span>
    <span class="token comment">/**
     * 列表头样式
     * @param headerColor
     * @return
     */</span>
    <span class="token keyword">public</span> <span class="token class-name">CellStyle</span> <span class="token function">getHeaderStyle</span><span class="token punctuation">(</span><span class="token keyword">short</span> headerColor<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">/**
     * 标题样式
     * @param color
     * @return
     */</span>
    <span class="token keyword">public</span> <span class="token class-name">CellStyle</span> <span class="token function">getTitleStyle</span><span class="token punctuation">(</span><span class="token keyword">short</span> color<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">/**
     * 获取样式方法
     * @param Parity
     * @param entity
     * @return
     */</span>
    <span class="token keyword">public</span> <span class="token class-name">CellStyle</span> <span class="token function">getStyles</span><span class="token punctuation">(</span><span class="token keyword">boolean</span> <span class="token class-name">Parity</span><span class="token punctuation">,</span> <span class="token class-name">ExcelExportEntity</span> entity<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</pre><p><strong>实现类尽量复用已经创建的Styler,切记</strong><br>
这样路飞先造了一个带边框的styler  ,<strong>ExcelExportStylerBorderImpl</strong><br>
效果如下<br>
<img src="./easypoi_files/11203544_eOw4.png" alt="2.6-1" title="边框"><br>
然后路飞又手痒写了个带换行颜色的  <strong>ExcelExportStylerColorImpl</strong><br>
效果如下<br>
<img src="./easypoi_files/11203718_miwu.png" alt="2.6-2" title="在这里输入图片标题"></p>
<p>客官看到这里应该就大体理解了我们的实现方法了吧,<br>
最后路飞实现了一个复杂的按照老师要求的样式交差了</p>
<hr>
<p>styler接口用法<br>
上面两个表头和标题样式不用解释<br>
后面这个是传入当前列的以及奇偶行,用户可以根据需求实现业务,包括去掉Excel的小箭头(也就是设置数字为数字格式的Cell),完成居中,字体等等各式各样的需求<br>
但是这里无法实现特别没的Excel,如果有这种需求可以使用模板来实现,在Excel点点就可以完美实现</p>
<h2 class="mume-header" id="305" ebook-toc-level-2="" heading="2.7 &amp;#x5982;&amp;#x4F55;&amp;#x81EA;&amp;#x5B9A;&amp;#x4E49;&amp;#x6570;&amp;#x636E;&amp;#x5904;&amp;#x7406;">2.7 如何自定义数据处理</h2>

<p>导入导出总有一些自定义格式转换,EasyPoi虽然定义了很多服务,但是也无法满足所有客户的需求,这个时候就需要咱们自己定义数据处理<br>
EasyPoi提供了</p>
<pre data-role="codeBlock" data-info="java" class="language-java"><span class="token comment">/**
 * Excel 导入导出 数据处理接口
 * 
 * @author JueYue
 *  2014年6月19日 下午11:59:45
 */</span>
<span class="token keyword">public</span> <span class="token keyword">interface</span> <span class="token class-name">IExcelDataHandler</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">&gt;</span></span> <span class="token punctuation">{</span>

    <span class="token comment">/**
     * 导出处理方法
     * 
     * @param obj
     *            当前对象
     * @param name
     *            当前字段名称
     * @param value
     *            当前值
     * @return
     */</span>
    <span class="token keyword">public</span> <span class="token class-name">Object</span> <span class="token function">exportHandler</span><span class="token punctuation">(</span><span class="token class-name">T</span> obj<span class="token punctuation">,</span> <span class="token class-name">String</span> name<span class="token punctuation">,</span> <span class="token class-name">Object</span> value<span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token comment">/**
     * 获取需要处理的字段,导入和导出统一处理了, 减少书写的字段
     * 
     * @return
     */</span>
    <span class="token keyword">public</span> <span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token function">getNeedHandlerFields</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token comment">/**
     * 导入处理方法 当前对象,当前字段名称,当前值
     * 
     * @param obj
     *            当前对象
     * @param name
     *            当前字段名称
     * @param value
     *            当前值
     * @return
     */</span>
    <span class="token keyword">public</span> <span class="token class-name">Object</span> <span class="token function">importHandler</span><span class="token punctuation">(</span><span class="token class-name">T</span> obj<span class="token punctuation">,</span> <span class="token class-name">String</span> name<span class="token punctuation">,</span> <span class="token class-name">Object</span> value<span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token comment">/**
     * 设置需要处理的属性列表
     * @param fields
     */</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">setNeedHandlerFields</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> fields<span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token comment">/**
     * 设置Map导入,自定义 put
     * @param map
     * @param originKey
     * @param value
     */</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">setMapValue</span><span class="token punctuation">(</span><span class="token class-name">Map</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span></span> map<span class="token punctuation">,</span> <span class="token class-name">String</span> originKey<span class="token punctuation">,</span> <span class="token class-name">Object</span> value<span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token comment">/**
     * 获取这个字段的 Hyperlink ,07版本需要,03版本不需要
     * @param creationHelper
     * @param obj
     * @param name
     * @param value
     * @return
     */</span>
    <span class="token keyword">public</span> <span class="token class-name">Hyperlink</span> <span class="token function">getHyperlink</span><span class="token punctuation">(</span><span class="token class-name">CreationHelper</span> creationHelper<span class="token punctuation">,</span> <span class="token class-name">T</span> obj<span class="token punctuation">,</span> <span class="token class-name">String</span> name<span class="token punctuation">,</span> <span class="token class-name">Object</span> value<span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token punctuation">}</span>
</pre><p>简单的使用方法如下</p>
<pre data-role="codeBlock" data-info="java" class="language-java"> <span class="token class-name">CourseHandler</span> hanlder <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">CourseHandler</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        hanlder<span class="token punctuation">.</span><span class="token function">setNeedHandlerFields</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token punctuation">{</span> <span class="token string">"课程名称"</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        exportParams<span class="token punctuation">.</span><span class="token function">setDataHandler</span><span class="token punctuation">(</span>hanlder<span class="token punctuation">)</span><span class="token punctuation">;</span>
</pre><p>我们自己实现以下这个类,也可以继承ExcelDataHandlerDefaultImpl ,避免实现多余的接口<br>
setNeedHandlerFields 这个是需要我们自己处理的字段,需要手动设置</p>
<p>让我们看一个demo</p>
<pre data-role="codeBlock" data-info="java" class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">MapImportHandler</span> <span class="token keyword">extends</span> <span class="token class-name">ExcelDataHandlerDefaultImpl</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Map</span><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span><span class="token punctuation">&gt;</span></span> <span class="token punctuation">{</span>

    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">setMapValue</span><span class="token punctuation">(</span><span class="token class-name">Map</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span></span> map<span class="token punctuation">,</span> <span class="token class-name">String</span> originKey<span class="token punctuation">,</span> <span class="token class-name">Object</span> value<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>value <span class="token keyword">instanceof</span> <span class="token class-name">Double</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token function">getRealKey</span><span class="token punctuation">(</span>originKey<span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token class-name">PoiPublicUtil</span><span class="token punctuation">.</span><span class="token function">doubleToString</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token class-name">Double</span><span class="token punctuation">)</span> value<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
            map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token function">getRealKey</span><span class="token punctuation">(</span>originKey<span class="token punctuation">)</span><span class="token punctuation">,</span> value <span class="token operator">!=</span> <span class="token keyword">null</span> <span class="token operator">?</span> value<span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">:</span> <span class="token keyword">null</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">private</span> <span class="token class-name">String</span> <span class="token function">getRealKey</span><span class="token punctuation">(</span><span class="token class-name">String</span> originKey<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>originKey<span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span><span class="token string">"交易账户"</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">return</span> <span class="token string">"accountNo"</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>originKey<span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span><span class="token string">"姓名"</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">return</span> <span class="token string">"name"</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>originKey<span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span><span class="token string">"客户类型"</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">return</span> <span class="token string">"type"</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token keyword">return</span> originKey<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</pre><p>这里我们在map导入的时候把map的key给转了,从中文转为习惯的英文</p>
<h2 class="mume-header" id="306" ebook-toc-level-2="" heading="2.8 Excel&amp;#x5BFC;&amp;#x5165;&amp;#x6821;&amp;#x9A8C;">2.8 Excel导入校验</h2>

<p>校验,是一个不可或缺的功能,现在java校验主要是JSR 303 规范,实现方式主流的有两种</p>
<ul>
<li>Hibernate Validator</li>
<li>Apache Commons Validator</li>
</ul>
<p>这个EasyPoi没有限制,只要你防止一个实现丢到maven中就可以了,但是Hibernate Validator用的貌似多一些<br>
之前的版本EasyPoi有定义自己的实现,但是后来抛弃了,没有必要造这种轮子,这个了功能已经够丰富了</p>
<h2 ebook-toc-level-2="" heading="&amp;#x4F7F;&amp;#x7528;" id="307">使用</h2>
<p><em><strong>对象</strong></em></p>
<p>EasyPoi的校验使用也很简单,对象上加上通用的校验规则或者这定义的这个看你用的哪个实现<br>
然后params.setNeedVerfiy(true);配置下需要校验就可以了<br>
看下具体的代码</p>
<pre data-role="codeBlock" data-info="java" class="language-java"> <span class="token comment">/**
     * Email校验
     */</span>
    <span class="token annotation punctuation">@Excel</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">"Email"</span><span class="token punctuation">,</span> width <span class="token operator">=</span> <span class="token number">25</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token class-name">String</span> email<span class="token punctuation">;</span>
    <span class="token comment">/**
     * 最大
     */</span>
    <span class="token annotation punctuation">@Excel</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">"Max"</span><span class="token punctuation">)</span>
    <span class="token annotation punctuation">@Max</span><span class="token punctuation">(</span>value <span class="token operator">=</span> <span class="token number">15</span><span class="token punctuation">,</span>message <span class="token operator">=</span> <span class="token string">"max 最大值不能超过15"</span> <span class="token punctuation">,</span>groups <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token class-name">ViliGroupOne</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">}</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token keyword">int</span>    max<span class="token punctuation">;</span>
    <span class="token comment">/**
     * 最小
     */</span>
    <span class="token annotation punctuation">@Excel</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">"Min"</span><span class="token punctuation">)</span>
    <span class="token annotation punctuation">@Min</span><span class="token punctuation">(</span>value <span class="token operator">=</span> <span class="token number">3</span><span class="token punctuation">,</span> groups <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token class-name">ViliGroupTwo</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">}</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token keyword">int</span>    min<span class="token punctuation">;</span>
    <span class="token comment">/**
     * 非空校验
     */</span>
    <span class="token annotation punctuation">@Excel</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">"NotNull"</span><span class="token punctuation">)</span>
    <span class="token annotation punctuation">@NotNull</span>
    <span class="token keyword">private</span> <span class="token class-name">String</span> notNull<span class="token punctuation">;</span>
    <span class="token comment">/**
     * 正则校验
     */</span>
    <span class="token annotation punctuation">@Excel</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">"Regex"</span><span class="token punctuation">)</span>
    <span class="token annotation punctuation">@Pattern</span><span class="token punctuation">(</span>regexp <span class="token operator">=</span> <span class="token string">"[\u4E00-\u9FA5]*"</span><span class="token punctuation">,</span> message <span class="token operator">=</span> <span class="token string">"不是中文"</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token class-name">String</span> regex<span class="token punctuation">;</span>
</pre><p>这里的校验规则都是JSR 303 的,使用方式也是的,这里就不做解释了<br>
然后使用方式是</p>
<pre data-role="codeBlock" data-info="java" class="language-java"><span class="token annotation punctuation">@Test</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">basetest</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">try</span> <span class="token punctuation">{</span>
            <span class="token class-name">ImportParams</span> params <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ImportParams</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            params<span class="token punctuation">.</span><span class="token function">setNeedVerfiy</span><span class="token punctuation">(</span><span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            params<span class="token punctuation">.</span><span class="token function">setVerfiyGroup</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">Class</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">{</span><span class="token class-name">ViliGroupOne</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token class-name">ExcelImportResult</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">ExcelVerifyEntity</span><span class="token punctuation">&gt;</span></span> result <span class="token operator">=</span> <span class="token class-name">ExcelImportUtil</span><span class="token punctuation">.</span><span class="token function">importExcelMore</span><span class="token punctuation">(</span>
                <span class="token keyword">new</span> <span class="token class-name">File</span><span class="token punctuation">(</span><span class="token class-name">PoiPublicUtil</span><span class="token punctuation">.</span><span class="token function">getWebRootPath</span><span class="token punctuation">(</span><span class="token string">"import/verfiy.xlsx"</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                <span class="token class-name">ExcelVerifyEntity</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">,</span> params<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token class-name">FileOutputStream</span> fos <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">FileOutputStream</span><span class="token punctuation">(</span><span class="token string">"D:/excel/ExcelVerifyTest.basetest.xlsx"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            result<span class="token punctuation">.</span><span class="token function">getWorkbook</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">write</span><span class="token punctuation">(</span>fos<span class="token punctuation">)</span><span class="token punctuation">;</span>
            fos<span class="token punctuation">.</span><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> result<span class="token punctuation">.</span><span class="token function">getList</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">size</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token class-name">ReflectionToStringBuilder</span><span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span>result<span class="token punctuation">.</span><span class="token function">getList</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span>i<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
            <span class="token class-name">Assert</span><span class="token punctuation">.</span><span class="token function">assertTrue</span><span class="token punctuation">(</span>result<span class="token punctuation">.</span><span class="token function">getList</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">size</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">==</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token class-name">Assert</span><span class="token punctuation">.</span><span class="token function">assertTrue</span><span class="token punctuation">(</span>result<span class="token punctuation">.</span><span class="token function">isVerfiyFail</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">Exception</span> e<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            LOGGER<span class="token punctuation">.</span><span class="token function">error</span><span class="token punctuation">(</span>e<span class="token punctuation">.</span><span class="token function">getMessage</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>e<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
</pre><p>***ExcelImportResult ***</p>
<p>我们会返回一个ExcelImportResult 对象,比我们平时返回的list多了一些元素</p>
<pre data-role="codeBlock" data-info="java" class="language-java"> <span class="token comment">/**
     * 结果集
     */</span>
    <span class="token keyword">private</span> <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">&gt;</span></span>  list<span class="token punctuation">;</span>

    <span class="token comment">/**
     * 是否存在校验失败
     */</span>
    <span class="token keyword">private</span> <span class="token keyword">boolean</span>  verfiyFail<span class="token punctuation">;</span>

    <span class="token comment">/**
     * 数据源
     */</span>
    <span class="token keyword">private</span> <span class="token class-name">Workbook</span> workbook<span class="token punctuation">;</span>
</pre><p>一个是集合,是一个是是否有校验失败的数据,一个原本的文档,但是在文档后面追加了错误信息</p>
<p><em><strong>注意,这里的list,有两种返回</strong></em></p>
<ul>
<li>一种是只返回正确的数据</li>
<li>一种是返回全部的数据,但是要求这个对象必须实现IExcelModel接口,如下</li>
</ul>
<p><em><strong>IExcelModel</strong></em></p>
<pre data-role="codeBlock" data-info="java" class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">ExcelVerifyEntityOfMode</span> <span class="token keyword">extends</span> <span class="token class-name">ExcelVerifyEntity</span> <span class="token keyword">implements</span> <span class="token class-name">IExcelModel</span> <span class="token punctuation">{</span>

    <span class="token keyword">private</span> <span class="token class-name">String</span> errorMsg<span class="token punctuation">;</span>

    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token class-name">String</span> <span class="token function">getErrorMsg</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> errorMsg<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">setErrorMsg</span><span class="token punctuation">(</span><span class="token class-name">String</span> errorMsg<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>errorMsg <span class="token operator">=</span> errorMsg<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

<span class="token punctuation">}</span>
</pre><p>*<strong>IExcelDataModel</strong><br>
获取错误数据的行号</p>
<pre data-role="codeBlock" data-info="java" class="language-java"><span class="token keyword">public</span> <span class="token keyword">interface</span> <span class="token class-name">IExcelDataModel</span> <span class="token punctuation">{</span>

    <span class="token comment">/**
     * 获取行号
     * @return
     */</span>
    <span class="token keyword">public</span> <span class="token keyword">int</span> <span class="token function">getRowNum</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token comment">/**
     *  设置行号
     * @param rowNum
     */</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">setRowNum</span><span class="token punctuation">(</span><span class="token keyword">int</span> rowNum<span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token punctuation">}</span>
</pre><p>需要对象实现这个接口</p>
<p>每行的错误数据也会填到这个错误信息中,方便用户后面自定义处理<br>
看下代码</p>
<pre data-role="codeBlock" data-info="java" class="language-java">   <span class="token annotation punctuation">@Test</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">baseModetest</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">try</span> <span class="token punctuation">{</span>
            <span class="token class-name">ImportParams</span> params <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ImportParams</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            params<span class="token punctuation">.</span><span class="token function">setNeedVerfiy</span><span class="token punctuation">(</span><span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token class-name">ExcelImportResult</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">ExcelVerifyEntityOfMode</span><span class="token punctuation">&gt;</span></span> result <span class="token operator">=</span> <span class="token class-name">ExcelImportUtil</span><span class="token punctuation">.</span><span class="token function">importExcelMore</span><span class="token punctuation">(</span>
                    <span class="token keyword">new</span> <span class="token class-name">FileInputStream</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">File</span><span class="token punctuation">(</span><span class="token class-name">PoiPublicUtil</span><span class="token punctuation">.</span><span class="token function">getWebRootPath</span><span class="token punctuation">(</span><span class="token string">"import/verfiy.xlsx"</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                <span class="token class-name">ExcelVerifyEntityOfMode</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">,</span> params<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token class-name">FileOutputStream</span> fos <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">FileOutputStream</span><span class="token punctuation">(</span><span class="token string">"D:/excel/baseModetest.xlsx"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            result<span class="token punctuation">.</span><span class="token function">getWorkbook</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">write</span><span class="token punctuation">(</span>fos<span class="token punctuation">)</span><span class="token punctuation">;</span>
            fos<span class="token punctuation">.</span><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> result<span class="token punctuation">.</span><span class="token function">getList</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">size</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token class-name">ReflectionToStringBuilder</span><span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span>result<span class="token punctuation">.</span><span class="token function">getList</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span>i<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
            <span class="token class-name">Assert</span><span class="token punctuation">.</span><span class="token function">assertTrue</span><span class="token punctuation">(</span>result<span class="token punctuation">.</span><span class="token function">getList</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">size</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">==</span> <span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">Exception</span> e<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            LOGGER<span class="token punctuation">.</span><span class="token function">error</span><span class="token punctuation">(</span>e<span class="token punctuation">.</span><span class="token function">getMessage</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>e<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
</pre><p><em><strong>IExcelVerifyHandler</strong></em></p>
<p>加入上面的不满足你,你可以用接口实现自己的校验规则,比如唯一性校验,等等,需要返回错误信息和成功与否</p>
<pre data-role="codeBlock" data-info="java" class="language-java"><span class="token keyword">public</span> <span class="token keyword">interface</span> <span class="token class-name">IExcelVerifyHandler</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">&gt;</span></span> <span class="token punctuation">{</span>

    <span class="token comment">/**
     * 导入校验方法
     * 
     * @param obj
     *            当前对象
     * @return
     */</span>
    <span class="token keyword">public</span> <span class="token class-name">ExcelVerifyHanlderResult</span> <span class="token function">verifyHandler</span><span class="token punctuation">(</span><span class="token class-name">T</span> obj<span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token punctuation">}</span>
</pre><p>调用顺序是先通用的,再接口,到这里校验的就完整了,下面给大家看下错误的excel返回<br>
<img src="./easypoi_files/18141356_UPlR.png" alt="yy" title="错误返回"></p>
<h2 class="mume-header" id="308" ebook-toc-level-2="" heading="2.9 Excel &amp;#x5927;&amp;#x6570;&amp;#x636E;&amp;#x8BFB;&amp;#x53D6;">2.9 Excel 大数据读取</h2>

<p>大数据量,避免内存溢出,以及提升读取效率,最好行数在10万行级别以上使用,否则我感觉意义不算大</p>
<h3 class="mume-header" id="90801" ebook-toc-level-3="" heading="2.9.1 ExceL by sax&amp;#x8BFB;&amp;#x53D6;">2.9.1 ExceL by sax读取</h3>

<p>by sax这个函数经过几轮修改,也差不多勉强到达可以用的环节了下面讲解下如何使用,修改来就该去就剩这一个方法了,不在返回数据用户自己实现IReadHandler来保存数据,不提供错误校验</p>
<pre data-role="codeBlock" data-info="java" class="language-java"><span class="token comment">/**
     * Excel 通过SAX解析方法,适合大数据导入,不支持图片
     * 导入 数据源本地文件,不返回校验结果 导入 字 段类型 Integer,Long,Double,Date,String,Boolean
     * 
     * @param inputstream
     * @param pojoClass
     * @param params
     * @param handler
     */</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">importExcelBySax</span><span class="token punctuation">(</span><span class="token class-name">InputStream</span> inputstream<span class="token punctuation">,</span> <span class="token class-name">Class</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span><span class="token punctuation">&gt;</span></span> pojoClass<span class="token punctuation">,</span>
                                        <span class="token class-name">ImportParams</span> params<span class="token punctuation">,</span> <span class="token class-name">IReadHandler</span> handler<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">new</span> <span class="token class-name">SaxReadExcel</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">readExcel</span><span class="token punctuation">(</span>inputstream<span class="token punctuation">,</span> pojoClass<span class="token punctuation">,</span> params<span class="token punctuation">,</span> handler<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</pre><p>主要是自己实现IReadHandler,easypoi解析完每个对象都会调用,handler方法,全部解析完成后会调用doAfterAll 方法</p>
<pre data-role="codeBlock" data-info="java" class="language-java">    <span class="token keyword">public</span> <span class="token keyword">interface</span> <span class="token class-name">IReadHandler</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">&gt;</span></span> <span class="token punctuation">{</span>
        <span class="token comment">/**
        * 处理解析对象
        * @param t
        */</span>
        <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">handler</span><span class="token punctuation">(</span><span class="token class-name">T</span> t<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">/**
        * 处理完成之后的业务
        */</span>
        <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">doAfterAll</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token punctuation">}</span>
</pre><pre class="language-text">- 不支持校验
- 不支持图片
- 不支持一对多
</pre>
<p>Demo如下,基本用法和其他的没啥去呗,自己处理handler就可以了</p>
<pre data-role="codeBlock" data-info="java" class="language-java"> <span class="token annotation punctuation">@Test</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">test</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">try</span> <span class="token punctuation">{</span>
            <span class="token class-name">ImportParams</span> params <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ImportParams</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            params<span class="token punctuation">.</span><span class="token function">setTitleRows</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">long</span> start <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getTime</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token class-name">ExcelImportUtil</span><span class="token punctuation">.</span><span class="token function">importExcelBySax</span><span class="token punctuation">(</span>
                    <span class="token keyword">new</span> <span class="token class-name">FileInputStream</span><span class="token punctuation">(</span>
                            <span class="token keyword">new</span> <span class="token class-name">File</span><span class="token punctuation">(</span><span class="token string">"import/ExcelExportMsgClient.xlsx"</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                    <span class="token class-name">MsgClient</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">,</span> params<span class="token punctuation">,</span> <span class="token keyword">new</span> <span class="token class-name">IReadHandler</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">MsgClient</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                        <span class="token annotation punctuation">@Override</span>
                        <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">handler</span><span class="token punctuation">(</span><span class="token class-name">MsgClient</span> o<span class="token punctuation">)</span> <span class="token punctuation">{</span>
                            <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token class-name">ReflectionToStringBuilder</span><span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span>o<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                        <span class="token punctuation">}</span>

                        <span class="token annotation punctuation">@Override</span>
                        <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">doAfterAll</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>

                        <span class="token punctuation">}</span>
                    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">FileNotFoundException</span> e<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token comment">// TODO Auto-generated catch block</span>
            e<span class="token punctuation">.</span><span class="token function">printStackTrace</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
</pre><h3 class="mume-header" id="90802" ebook-toc-level-3="" heading="2.9.2 CSV&amp;#x5BFC;&amp;#x5165;">2.9.2 CSV导入</h3>

<pre class="language-text">csv处理参考 ##7.1
</pre>
<h2 class="mume-header" id="309" ebook-toc-level-2="" heading="2.10 Excel&amp;#x5927;&amp;#x6570;&amp;#x636E;&amp;#x5BFC;&amp;#x51FA;">2.10 Excel大数据导出</h2>

<p>大数据导出是当我们的导出数量在几万,到上百万的数据时,一次从数据库查询这么多数据加载到内存然后写入会对我们的内存和CPU都产生压力,这个时候需要我们像分页一样处理导出分段写入Excel缓解Excel的压力 EasyPoi提供的是两个方法 ***强制使用 xssf版本的Excel ***</p>
<pre data-role="codeBlock" data-info="java" class="language-java">  <span class="token comment">/**
     * @param entity
     *            表格标题属性
     * @param pojoClass
     *            Excel对象Class
     * @param dataSet
     *            Excel对象数据List
     */</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token class-name">Workbook</span> <span class="token function">exportBigExcel</span><span class="token punctuation">(</span><span class="token class-name">ExportParams</span> entity<span class="token punctuation">,</span> <span class="token class-name">Class</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span><span class="token punctuation">&gt;</span></span> pojoClass<span class="token punctuation">,</span>
                                          <span class="token class-name">Collection</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span><span class="token punctuation">&gt;</span></span> dataSet<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token class-name">ExcelBatchExportServer</span> batachServer <span class="token operator">=</span> <span class="token class-name">ExcelBatchExportServer</span>
            <span class="token punctuation">.</span><span class="token function">getExcelBatchExportServer</span><span class="token punctuation">(</span>entity<span class="token punctuation">,</span> pojoClass<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">return</span> batachServer<span class="token punctuation">.</span><span class="token function">appendData</span><span class="token punctuation">(</span>dataSet<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">closeExportBigExcel</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token class-name">ExcelBatchExportServer</span> batachServer <span class="token operator">=</span> <span class="token class-name">ExcelBatchExportServer</span><span class="token punctuation">.</span><span class="token function">getExcelBatchExportServer</span><span class="token punctuation">(</span><span class="token keyword">null</span><span class="token punctuation">,</span>
            <span class="token keyword">null</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        batachServer<span class="token punctuation">.</span><span class="token function">closeExportBigExcel</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</pre><p>添加数据和关闭服务,关闭服务不是必须的,可以调也可以不掉<br>
我们只需要for循环写入Excel就可以了</p>
<pre data-role="codeBlock" data-info="java" class="language-java"><span class="token annotation punctuation">@Test</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">bigDataExport</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">throws</span> <span class="token class-name">Exception</span> <span class="token punctuation">{</span>

        <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">MsgClient</span><span class="token punctuation">&gt;</span></span> list <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ArrayList</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">MsgClient</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">Workbook</span> workbook <span class="token operator">=</span> <span class="token keyword">null</span><span class="token punctuation">;</span>
        <span class="token class-name">Date</span> start <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">ExportParams</span> params <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ExportParams</span><span class="token punctuation">(</span><span class="token string">"大数据测试"</span><span class="token punctuation">,</span> <span class="token string">"测试"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> <span class="token number">1000000</span><span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>  <span class="token comment">//一百万数据量</span>
            <span class="token class-name">MsgClient</span> client <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">MsgClient</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            client<span class="token punctuation">.</span><span class="token function">setBirthday</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            client<span class="token punctuation">.</span><span class="token function">setClientName</span><span class="token punctuation">(</span><span class="token string">"小明"</span> <span class="token operator">+</span> i<span class="token punctuation">)</span><span class="token punctuation">;</span>
            client<span class="token punctuation">.</span><span class="token function">setClientPhone</span><span class="token punctuation">(</span><span class="token string">"18797"</span> <span class="token operator">+</span> i<span class="token punctuation">)</span><span class="token punctuation">;</span>
            client<span class="token punctuation">.</span><span class="token function">setCreateBy</span><span class="token punctuation">(</span><span class="token string">"JueYue"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            client<span class="token punctuation">.</span><span class="token function">setId</span><span class="token punctuation">(</span><span class="token string">"1"</span> <span class="token operator">+</span> i<span class="token punctuation">)</span><span class="token punctuation">;</span>
            client<span class="token punctuation">.</span><span class="token function">setRemark</span><span class="token punctuation">(</span><span class="token string">"测试"</span> <span class="token operator">+</span> i<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token class-name">MsgClientGroup</span> group <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">MsgClientGroup</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            group<span class="token punctuation">.</span><span class="token function">setGroupName</span><span class="token punctuation">(</span><span class="token string">"测试"</span> <span class="token operator">+</span> i<span class="token punctuation">)</span><span class="token punctuation">;</span>
            client<span class="token punctuation">.</span><span class="token function">setGroup</span><span class="token punctuation">(</span>group<span class="token punctuation">)</span><span class="token punctuation">;</span>
            list<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>client<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">if</span><span class="token punctuation">(</span>list<span class="token punctuation">.</span><span class="token function">size</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">==</span> <span class="token number">10000</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
                workbook <span class="token operator">=</span> <span class="token class-name">ExcelExportUtil</span><span class="token punctuation">.</span><span class="token function">exportBigExcel</span><span class="token punctuation">(</span>params<span class="token punctuation">,</span> <span class="token class-name">MsgClient</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">,</span> list<span class="token punctuation">)</span><span class="token punctuation">;</span>
                list<span class="token punctuation">.</span><span class="token function">clear</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
        <span class="token class-name">ExcelExportUtil</span><span class="token punctuation">.</span><span class="token function">closeExportBigExcel</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getTime</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">-</span> start<span class="token punctuation">.</span><span class="token function">getTime</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">File</span> savefile <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">File</span><span class="token punctuation">(</span><span class="token string">"D:/excel/"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>savefile<span class="token punctuation">.</span><span class="token function">exists</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            savefile<span class="token punctuation">.</span><span class="token function">mkdirs</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token class-name">FileOutputStream</span> fos <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">FileOutputStream</span><span class="token punctuation">(</span><span class="token string">"D:/excel/ExcelExportBigData.bigDataExport.xlsx"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        workbook<span class="token punctuation">.</span><span class="token function">write</span><span class="token punctuation">(</span>fos<span class="token punctuation">)</span><span class="token punctuation">;</span>
        fos<span class="token punctuation">.</span><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

</pre><p>生成的Excel数据<br>
<img src="./easypoi_files/07174436_1jDz.png" alt="测试结果" title="在这里输入图片标题"></p>
<p>Cpu和内存<br>
<img src="./easypoi_files/07174540_2ic5.png" alt="CPU和内存" title="在这里输入图片标题"></p>
<p>多次测试用时统计,速度还是可以接受的,^^</p>
<table>
<thead>
<tr>
<th>数据量</th>
<th>用时</th>
<th>文件大小</th>
<th>列数</th>
</tr>
</thead>
<tbody>
<tr>
<td>100W</td>
<td>16.4s</td>
<td>24.3MB</td>
<td>5</td>
</tr>
<tr>
<td>100W</td>
<td>15.9s</td>
<td>24.3MB</td>
<td>5</td>
</tr>
<tr>
<td>200W</td>
<td>29.5s</td>
<td>48.5MB</td>
<td>5</td>
</tr>
<tr>
<td>100W</td>
<td>30.8s</td>
<td>37.8MB</td>
<td>10</td>
</tr>
<tr>
<td>200W</td>
<td>58.7s</td>
<td>76.1MB</td>
<td>10</td>
</tr>
</tbody>
</table>
<h2 class="mume-header" id="310" ebook-toc-level-2="" heading="2.11 &amp;#x5BFC;&amp;#x5165;&amp;#x83B7;&amp;#x53D6;Key-Value">2.11 导入获取Key-Value</h2>

<p>from 3.0.1<br>
工作中是否会遇到导入读取一些特定的字段比如<br>
<img src="./easypoi_files/11093955_h1Df.png" alt="导入图片" title="导入图片"><br>
Excel 中的委托方,代理方,日期,单号,或者尾部的身份证号,电话等等,需要我们统一入库,这些字段没有具体位置,只能特定计算<br>
这里给出了一个全新的解决办法 key-value 导入方法<br>
key 是要导入的字段名称比如 委托方: 就认为是一个要导入的字段,后面的一个cell就是起对应的值<br>
比如委托方：	一众科技有限公司  这样导入进去就是 key委托方,value 一众科技有限公司<br>
示例代码</p>
<pre data-role="codeBlock" data-info="java" class="language-java"><span class="token annotation punctuation">@Test</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">test</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">try</span> <span class="token punctuation">{</span>
            <span class="token class-name">ImportParams</span> params <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ImportParams</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            params<span class="token punctuation">.</span><span class="token function">setKeyMark</span><span class="token punctuation">(</span><span class="token string">"："</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            params<span class="token punctuation">.</span><span class="token function">setReadSingleCell</span><span class="token punctuation">(</span><span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            params<span class="token punctuation">.</span><span class="token function">setTitleRows</span><span class="token punctuation">(</span><span class="token number">7</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            params<span class="token punctuation">.</span><span class="token function">setLastOfInvalidRow</span><span class="token punctuation">(</span><span class="token number">9</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token class-name">ExcelImportResult</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Map</span><span class="token punctuation">&gt;</span></span> result <span class="token operator">=</span> <span class="token class-name">ExcelImportUtil</span><span class="token punctuation">.</span><span class="token function">importExcelMore</span><span class="token punctuation">(</span>
                    <span class="token keyword">new</span> <span class="token class-name">File</span><span class="token punctuation">(</span><span class="token class-name">PoiPublicUtil</span><span class="token punctuation">.</span><span class="token function">getWebRootPath</span><span class="token punctuation">(</span><span class="token string">"import/业务委托单.xlsx"</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                    <span class="token class-name">Map</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">,</span> params<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> result<span class="token punctuation">.</span><span class="token function">getList</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">size</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>result<span class="token punctuation">.</span><span class="token function">getList</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span>i<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
            <span class="token class-name">Assert</span><span class="token punctuation">.</span><span class="token function">assertTrue</span><span class="token punctuation">(</span>result<span class="token punctuation">.</span><span class="token function">getList</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">size</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">==</span> <span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>result<span class="token punctuation">.</span><span class="token function">getMap</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">Exception</span> e<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            LOGGER<span class="token punctuation">.</span><span class="token function">error</span><span class="token punctuation">(</span>e<span class="token punctuation">.</span><span class="token function">getMessage</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>e<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
</pre><p>需要设置两个或者一个值<br>
params.setKeyMark("：");   判断一个cell是key的规则,可以自定义,默认就是 ":"<br>
params.setReadSingleCell(true);  是否需要读取这种单独的sql<br>
读取完毕后,通过result.getMap() 就可以拿到自己想要的值了比如上面的Excel读取到的map就是</p>
<p>{境内详细收货地址、联系人、电话：=1.3112345678E10, 委托方：=一众科技有限公司, 代理方：=上海一众金融信息服务有限公司, 委托单号：=XH-HZHY-20170504, 日期：=2017.5.4, 供应商交货方式：=, 合计：=, 境内交货方式：=, 指定收货人身份证号：=3.7082719880102099E17}</p>
<p>这样就比较方便的处理较为复杂的Excel导入了</p>
<h2 class="mume-header" id="311" ebook-toc-level-2="" heading="2.12 groupname&amp;#x548C;ExcelEntity&amp;#x7684;name&amp;#x5C5E;&amp;#x6027;">2.12 groupname和ExcelEntity的name属性</h2>

<p>之前一直没想好，双号表头如何处理数据，直到前几天突然想到了groupname这个属性，下面先介绍下这两个属性解决的问题，也是之前很多朋友问到的问题<br>
<img src="./easypoi_files/20112857_np8y.png" alt="aaa大" title="在这里输入图片标题"><br>
这种双行的表头，之前只有在集合的模式情况下才会支持，但是很多情况都不是集合模式，也只是一列数据，</p>
<ul>
<li>简单的groupname</li>
</ul>
<p>比如这里的时间算是两个时间的聚合，单也是对象当中的元素而已，我们要导出这样的数据现在只要设置下groupname就可以了</p>
<pre data-role="codeBlock" data-info="java" class="language-java"><span class="token annotation punctuation">@Excel</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">"电话号码"</span><span class="token punctuation">,</span> groupName <span class="token operator">=</span> <span class="token string">"联系方式"</span><span class="token punctuation">,</span> orderNum <span class="token operator">=</span> <span class="token string">"1"</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token class-name">String</span> clientPhone <span class="token operator">=</span> <span class="token keyword">null</span><span class="token punctuation">;</span>
    <span class="token comment">// 客户姓名</span>
    <span class="token annotation punctuation">@Excel</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">"姓名"</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token class-name">String</span> clientName <span class="token operator">=</span> <span class="token keyword">null</span><span class="token punctuation">;</span>
    <span class="token comment">// 备注</span>
    <span class="token annotation punctuation">@Excel</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">"备注"</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token class-name">String</span> remark <span class="token operator">=</span> <span class="token keyword">null</span><span class="token punctuation">;</span>
    <span class="token comment">// 生日</span>
    <span class="token annotation punctuation">@Excel</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">"出生日期"</span><span class="token punctuation">,</span> format <span class="token operator">=</span> <span class="token string">"yyyy-MM-dd"</span><span class="token punctuation">,</span> width <span class="token operator">=</span> <span class="token number">20</span><span class="token punctuation">,</span> groupName <span class="token operator">=</span> <span class="token string">"时间"</span><span class="token punctuation">,</span> orderNum <span class="token operator">=</span> <span class="token string">"2"</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token class-name">Date</span> birthday <span class="token operator">=</span> <span class="token keyword">null</span><span class="token punctuation">;</span>
    <span class="token comment">// 创建人</span>
    <span class="token annotation punctuation">@Excel</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">"创建时间"</span><span class="token punctuation">,</span> groupName <span class="token operator">=</span> <span class="token string">"时间"</span><span class="token punctuation">,</span> orderNum <span class="token operator">=</span> <span class="token string">"3"</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token class-name">String</span> createBy <span class="token operator">=</span> <span class="token keyword">null</span><span class="token punctuation">;</span>
</pre><p>这样就会把两个groupname合并到一起展示，使用也比较简单</p>
<ul>
<li>ExcelEntity 一个对象在一起</li>
</ul>
<p>假如我们需要一个对象属性统一在一起，name我们需要设置下这个对象的name属性，并且show=true 这两个是 且的关系<br>
比如</p>
<pre data-role="codeBlock" data-info="java" class="language-java"> <span class="token annotation punctuation">@Excel</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">"电话号码"</span><span class="token punctuation">,</span> groupName <span class="token operator">=</span> <span class="token string">"联系方式"</span><span class="token punctuation">,</span> orderNum <span class="token operator">=</span> <span class="token string">"1"</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token class-name">String</span> clientPhone <span class="token operator">=</span> <span class="token keyword">null</span><span class="token punctuation">;</span>
    <span class="token annotation punctuation">@Excel</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">"姓名"</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token class-name">String</span> clientName <span class="token operator">=</span> <span class="token keyword">null</span><span class="token punctuation">;</span>
    <span class="token annotation punctuation">@ExcelEntity</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">"学生"</span><span class="token punctuation">,</span> show <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token class-name">GnStudentEntity</span> studentEntity<span class="token punctuation">;</span>
</pre><p>学生对象的内部就是普通的注解</p>
<pre data-role="codeBlock" data-info="java" class="language-java"><span class="token annotation punctuation">@Excel</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">"学生姓名"</span><span class="token punctuation">,</span> height <span class="token operator">=</span> <span class="token number">20</span><span class="token punctuation">,</span> width <span class="token operator">=</span> <span class="token number">30</span><span class="token punctuation">,</span> orderNum <span class="token operator">=</span> <span class="token string">"2"</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token class-name">String</span> name<span class="token punctuation">;</span>

    <span class="token annotation punctuation">@Excel</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">"学生性别"</span><span class="token punctuation">,</span> replace <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token string">"男_1"</span><span class="token punctuation">,</span> <span class="token string">"女_0"</span><span class="token punctuation">}</span><span class="token punctuation">,</span> suffix <span class="token operator">=</span> <span class="token string">"生"</span><span class="token punctuation">,</span> orderNum <span class="token operator">=</span> <span class="token string">"3"</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token keyword">int</span> sex<span class="token punctuation">;</span>

    <span class="token annotation punctuation">@Excel</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">"出生日期"</span><span class="token punctuation">,</span> format <span class="token operator">=</span> <span class="token string">"yyyy-MM-dd"</span><span class="token punctuation">,</span> width <span class="token operator">=</span> <span class="token number">20</span><span class="token punctuation">,</span> orderNum <span class="token operator">=</span> <span class="token string">"4"</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token class-name">Date</span> birthday<span class="token punctuation">;</span>

    <span class="token annotation punctuation">@Excel</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">"进校日期"</span><span class="token punctuation">,</span> format <span class="token operator">=</span> <span class="token string">"yyyy-MM-dd"</span><span class="token punctuation">,</span> orderNum <span class="token operator">=</span> <span class="token string">"5"</span><span class="token punctuation">)</span>
    <span class="token keyword">private</span> <span class="token class-name">Date</span> registrationDate<span class="token punctuation">;</span>
</pre><p>出来的效果如下<br>
<img src="./easypoi_files/20113530_FjBG.png" alt="输入图片说明" title="在这里输入图片标题"></p>
<p>使用起来还是很简单的，<strong>导入的话同样设置就可以获取到了</strong></p>
<ul>
<li>排序问题</li>
</ul>
<p>导出时，表头双行显示,聚合,排序以最小的值参与总体排序再内部排序<br>
导出排序跟定义了annotation的字段的顺序有关 可以使用a_id,b_id来确实是否使用<br>
优先弱与 @ExcelEntity 的name和show属性</p>
<p>简单说就是先排外部顺序，再排内部顺序</p>
<h2 class="mume-header" id="312" ebook-toc-level-2="" heading="2.13 &amp;#x591A;&amp;#x7EBF;&amp;#x7A0B;&amp;#x5BFC;&amp;#x5165;&amp;#x57FA;&amp;#x4E8E;ForkJoin @Since4.1">2.13 多线程导入基于ForkJoin @Since4.1</h2>

<p>鉴于4.0已经开始使用jdk8了,我们的功能也是时候升级下了,现在导入支持了fork/join的线程支持,使用限制<br>
1.因为是采用分隔读取的所以不支持一对多<br>
2.4.1是不支持图片的<br>
3.线程数我测试是根据CPU来的不知是否正确</p>
<p>使用方法很简单ImportParams 新加了两个参数,设置为true就可以了,critical是最新的分隔符,可以自定义下</p>
<pre data-role="codeBlock" data-info="java" class="language-java"><span class="token comment">/**
     * 是否并行计算
     */</span>
    <span class="token keyword">private</span> <span class="token keyword">boolean</span>             concurrentTask <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">;</span>
    <span class="token comment">/**
     * 最小截取大小
     */</span>
    <span class="token keyword">private</span> <span class="token class-name">Integer</span>             critical <span class="token operator">=</span> <span class="token number">1000</span><span class="token punctuation">;</span>
</pre><p>demo如下</p>
<pre data-role="codeBlock" data-info="java" class="language-java">  <span class="token annotation punctuation">@Test</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">testConCurrent</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">try</span> <span class="token punctuation">{</span>
            <span class="token class-name">Date</span> start <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            LOGGER<span class="token punctuation">.</span><span class="token function">debug</span><span class="token punctuation">(</span><span class="token string">"start"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token class-name">ImportParams</span> params <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ImportParams</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            params<span class="token punctuation">.</span><span class="token function">setTitleRows</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            params<span class="token punctuation">.</span><span class="token function">setConcurrentTask</span><span class="token punctuation">(</span><span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">MsgClient</span><span class="token punctuation">&gt;</span></span> result <span class="token operator">=</span> <span class="token class-name">ExcelImportUtil</span><span class="token punctuation">.</span><span class="token function">importExcel</span><span class="token punctuation">(</span>
                    <span class="token keyword">new</span> <span class="token class-name">File</span><span class="token punctuation">(</span><span class="token class-name">FileUtilTest</span><span class="token punctuation">.</span><span class="token function">getWebRootPath</span><span class="token punctuation">(</span><span class="token string">"import/BigDataExport.xlsx"</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                    <span class="token class-name">MsgClient</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">,</span> params<span class="token punctuation">)</span><span class="token punctuation">;</span>
            LOGGER<span class="token punctuation">.</span><span class="token function">debug</span><span class="token punctuation">(</span><span class="token string">"end,time is {}"</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getTime</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">-</span> start<span class="token punctuation">.</span><span class="token function">getTime</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token operator">/</span> <span class="token number">1000</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token class-name">Assert</span><span class="token punctuation">.</span><span class="token function">assertTrue</span><span class="token punctuation">(</span>result<span class="token punctuation">.</span><span class="token function">size</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">==</span> <span class="token number">200000</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> result<span class="token punctuation">.</span><span class="token function">size</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token class-name">Assert</span><span class="token punctuation">.</span><span class="token function">assertTrue</span><span class="token punctuation">(</span>result<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span>i<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getClientName</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">equalsIgnoreCase</span><span class="token punctuation">(</span><span class="token string">"小明"</span> <span class="token operator">+</span> i<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">Exception</span> e<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
</pre><p>我测试数据结果和正常读取的逾期是一直的</p>
<h1 class="mume-header" id="4" ebook-toc-level-1="" heading="3. Excel&amp;#x6A21;&amp;#x677F;&amp;#x5904;&amp;#x7406;">3. Excel模板处理</h1>

<h2 class="mume-header" id="401" ebook-toc-level-2="" heading="3.1 &amp;#x6A21;&amp;#x677F; &amp;#x6307;&amp;#x4EE4;&amp;#x4ECB;&amp;#x7ECD;">3.1 模板 指令介绍</h2>

<p>模板是处理复杂Excel的简单方法，复杂的Excel样式，可以用Excel直接编辑，完美的避开了代码编写样式的雷区，同时指令的支持，也提了模板的有效性<br>
下面列举下EasyPoi支持的指令以及作用，<strong>最主要的就是各种fe的用法</strong></p>
<ul>
<li>空格分割</li>
<li>三目运算  {{test ? obj:obj2}}</li>
<li>n: 表示 这个cell是数值类型 {{n:}}</li>
<li>le: 代表长度{{le:()}} 在if/else 运用{{le:() &gt; 8 ? obj1 :  obj2}}</li>
<li>fd: 格式化时间 {{fd:(obj;yyyy-MM-dd)}}</li>
<li>fn: 格式化数字 {{fn:(obj;###.00)}}</li>
<li>fe: 遍历数据,创建row</li>
<li>!fe: 遍历数据不创建row</li>
<li>$fe: 下移插入,把当前行,下面的行全部下移.size()行,然后插入</li>
<li>#fe: 横向遍历</li>
<li>v_fe: 横向遍历值</li>
<li>!if: 删除当前列 {{!if:(test)}}</li>
<li>单引号表示常量值 ''  比如'1' 那么输出的就是 1</li>
<li>&amp;NULL&amp; 空格</li>
<li>]] 换行符 多行遍历导出</li>
<li>sum： 统计数据</li>
</ul>
<p>整体风格和el表达式类似，大家应该也比较熟悉<br>
<strong>采用的写法是{{}}代表表达式，然后根据表达式里面的数据取值</strong></p>
<p>关于样式问题<br>
<strong>easypoi不会改变excel原有的样式，如果是遍历，easypoi会根据模板的那一行样式进行复制</strong></p>
<h2 ebook-toc-level-2="" heading="&amp;#x6D4B;&amp;#x8BD5;&amp;#x9879;&amp;#x76EE;" id="402">测试项目</h2>
<p>在cn.afterturn.easypoi.test.excel.template 这个目录下面<br>
<a href="https://gitee.com/lemur/easypoi-test/tree/master/src/test/java/cn/afterturn/easypoi/test/excel/template">https://gitee.com/lemur/easypoi-test/tree/master/src/test/java/cn/afterturn/easypoi/test/excel/template</a></p>
<h2 class="mume-header" id="403" ebook-toc-level-2="" heading="3.2 &amp;#x57FA;&amp;#x672C;&amp;#x5BFC;&amp;#x51FA;">3.2 基本导出</h2>

<p>看一个常见的到处模板--专项支出用款申请书<br>
<img src="./easypoi_files/26145656_oqzr.png" alt="模板s" title="在这里输入图片标题"><br>
这里面有正常的标签以及<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>f</mi><mi>e</mi><mi mathvariant="normal">遍</mi><mi mathvariant="normal">历</mi><mi mathvariant="normal">，</mi></mrow><annotation encoding="application/x-tex">fe遍历，</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord mathdefault" style="margin-right:0.10764em;">f</span><span class="mord mathdefault">e</span><span class="mord cjk_fallback">遍</span><span class="mord cjk_fallback">历</span><span class="mord cjk_fallback">，</span></span></span></span>fe遍历应该是使用最广的遍历，用来解决遍历后下面还有数据的处理方式<br>
我们要生成的是这个需要一些list集合和一些单纯的数据</p>
<p>fe的写法 fe标志 冒号 list数据 单个元素数据（默认t，可以不写） 第一个元素<br>
{{$fe: maplist t <a href="http://t.id/">t.id</a> }}</p>
<p>看下数据代码，主要是构造数据TemplateExportParams是主要的参数数据</p>
<pre data-role="codeBlock" data-info="java" class="language-java"><span class="token annotation punctuation">@Test</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">fe_map</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">throws</span> <span class="token class-name">Exception</span> <span class="token punctuation">{</span>
        <span class="token class-name">TemplateExportParams</span> params <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">TemplateExportParams</span><span class="token punctuation">(</span>
                <span class="token string">"WEB-INF/doc/专项支出用款申请书_map.xls"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">Map</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span></span> map <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">HashMap</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"date"</span><span class="token punctuation">,</span> <span class="token string">"2014-12-25"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"money"</span><span class="token punctuation">,</span> <span class="token number">2000000.00</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"upperMoney"</span><span class="token punctuation">,</span> <span class="token string">"贰佰万"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"company"</span><span class="token punctuation">,</span> <span class="token string">"执笔潜行科技有限公司"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"bureau"</span><span class="token punctuation">,</span> <span class="token string">"财政局"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"person"</span><span class="token punctuation">,</span> <span class="token string">"JueYue"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"phone"</span><span class="token punctuation">,</span> <span class="token string">"1879740****"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Map</span><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">String</span><span class="token punctuation">&gt;</span><span class="token punctuation">&gt;</span></span> listMap <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ArrayList</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Map</span><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">String</span><span class="token punctuation">&gt;</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> <span class="token number">4</span><span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token class-name">Map</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">String</span><span class="token punctuation">&gt;</span></span> lm <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">HashMap</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">String</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            lm<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"id"</span><span class="token punctuation">,</span> i <span class="token operator">+</span> <span class="token number">1</span> <span class="token operator">+</span> <span class="token string">""</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            lm<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"zijin"</span><span class="token punctuation">,</span> i <span class="token operator">*</span> <span class="token number">10000</span> <span class="token operator">+</span> <span class="token string">""</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            lm<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"bianma"</span><span class="token punctuation">,</span> <span class="token string">"A001"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            lm<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"mingcheng"</span><span class="token punctuation">,</span> <span class="token string">"设计"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            lm<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"xiangmumingcheng"</span><span class="token punctuation">,</span> <span class="token string">"EasyPoi "</span> <span class="token operator">+</span> i <span class="token operator">+</span> <span class="token string">"期"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            lm<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"quancheng"</span><span class="token punctuation">,</span> <span class="token string">"开源项目"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            lm<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"sqje"</span><span class="token punctuation">,</span> i <span class="token operator">*</span> <span class="token number">10000</span> <span class="token operator">+</span> <span class="token string">""</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            lm<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"hdje"</span><span class="token punctuation">,</span> i <span class="token operator">*</span> <span class="token number">10000</span> <span class="token operator">+</span> <span class="token string">""</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

            listMap<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>lm<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"maplist"</span><span class="token punctuation">,</span> listMap<span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token class-name">Workbook</span> workbook <span class="token operator">=</span> <span class="token class-name">ExcelExportUtil</span><span class="token punctuation">.</span><span class="token function">exportExcel</span><span class="token punctuation">(</span>params<span class="token punctuation">,</span> map<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">File</span> savefile <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">File</span><span class="token punctuation">(</span><span class="token string">"D:/excel/"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>savefile<span class="token punctuation">.</span><span class="token function">exists</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            savefile<span class="token punctuation">.</span><span class="token function">mkdirs</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token class-name">FileOutputStream</span> fos <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">FileOutputStream</span><span class="token punctuation">(</span><span class="token string">"D:/excel/专项支出用款申请书_map.xls"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        workbook<span class="token punctuation">.</span><span class="token function">write</span><span class="token punctuation">(</span>fos<span class="token punctuation">)</span><span class="token punctuation">;</span>
        fos<span class="token punctuation">.</span><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</pre><p>看下输出的效果<br>
<img src="./easypoi_files/26150826_DKZQ.png" alt="模板导出效果" title="在这里输入图片标题"></p>
<h2 class="mume-header" id="404" ebook-toc-level-2="" heading="3.3 &amp;#x6A21;&amp;#x677F;&amp;#x5F53;&amp;#x4E2D;&amp;#x4F7F;&amp;#x7528;&amp;#x6CE8;&amp;#x89E3;">3.3 模板当中使用注解</h2>

<h2 class="mume-header" id="405" ebook-toc-level-2="" heading="3.4 &amp;#x56FE;&amp;#x7247;&amp;#x5BFC;&amp;#x51FA;">3.4 图片导出</h2>

<p>模板图片导出，没有注解导出图片那么容易，但也不算复杂,构建一个ImageEntity<br>
设置下高宽，地址或者byte[]及可以了</p>
<pre data-role="codeBlock" data-info="java" class="language-java"><span class="token class-name">ImageEntity</span> image <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ImageEntity</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
image<span class="token punctuation">.</span><span class="token function">setHeight</span><span class="token punctuation">(</span><span class="token number">200</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
image<span class="token punctuation">.</span><span class="token function">setWidth</span><span class="token punctuation">(</span><span class="token number">500</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
image<span class="token punctuation">.</span><span class="token function">setUrl</span><span class="token punctuation">(</span><span class="token string">"imgs/company/baidu.png"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</pre><p>具体的导出代码</p>
<pre data-role="codeBlock" data-info="java" class="language-java"> <span class="token annotation punctuation">@Test</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">one</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">throws</span> <span class="token class-name">Exception</span> <span class="token punctuation">{</span>
        <span class="token class-name">TemplateExportParams</span> params <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">TemplateExportParams</span><span class="token punctuation">(</span>
                <span class="token string">"doc/exportTemp_image.xls"</span><span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">Map</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span></span> map <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">HashMap</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">// sheet 2</span>
        map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"month"</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">Map</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span></span> temp<span class="token punctuation">;</span>
        <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> <span class="token number">8</span><span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            temp <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">HashMap</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            temp<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"per"</span><span class="token punctuation">,</span> i <span class="token operator">*</span> <span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            temp<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"mon"</span><span class="token punctuation">,</span> i <span class="token operator">*</span> <span class="token number">1000</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            temp<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"summon"</span><span class="token punctuation">,</span> i <span class="token operator">*</span> <span class="token number">10000</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token class-name">ImageEntity</span> image <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ImageEntity</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            image<span class="token punctuation">.</span><span class="token function">setHeight</span><span class="token punctuation">(</span><span class="token number">200</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            image<span class="token punctuation">.</span><span class="token function">setWidth</span><span class="token punctuation">(</span><span class="token number">500</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            image<span class="token punctuation">.</span><span class="token function">setUrl</span><span class="token punctuation">(</span><span class="token string">"imgs/company/baidu.png"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            temp<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"image"</span><span class="token punctuation">,</span> image<span class="token punctuation">)</span><span class="token punctuation">;</span>
            map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"i"</span> <span class="token operator">+</span> i<span class="token punctuation">,</span> temp<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token class-name">Workbook</span> book <span class="token operator">=</span> <span class="token class-name">ExcelExportUtil</span><span class="token punctuation">.</span><span class="token function">exportExcel</span><span class="token punctuation">(</span>params<span class="token punctuation">,</span> map<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">File</span> savefile <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">File</span><span class="token punctuation">(</span><span class="token string">"D:/excel/"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>savefile<span class="token punctuation">.</span><span class="token function">exists</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            savefile<span class="token punctuation">.</span><span class="token function">mkdirs</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token class-name">FileOutputStream</span> fos <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">FileOutputStream</span><span class="token punctuation">(</span><span class="token string">"D:/excel/exportTemp_image.xls"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        book<span class="token punctuation">.</span><span class="token function">write</span><span class="token punctuation">(</span>fos<span class="token punctuation">)</span><span class="token punctuation">;</span>
        fos<span class="token punctuation">.</span><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token punctuation">}</span>
</pre><h2 class="mume-header" id="406" ebook-toc-level-2="" heading="3.5 clone sheet&amp;#x5BFC;&amp;#x51FA;&amp;#x591A;&amp;#x4E2A;&amp;#x6A21;&amp;#x677F;&amp;#x4E00;&amp;#x81F4;&amp;#x7684;&amp;#x8868;&amp;#x683C; @Since 4.1">3.5 clone sheet导出多个模板一致的表格 @Since 4.1</h2>

<p>poi4.0支持了sheet clone功能,这个为我们的一个模板导出N个sheet提供了基础支持,鉴于此该功能面世,使用也相当简单</p>
<pre data-role="codeBlock" data-info="java" class="language-java">    <span class="token comment">/**
     * 导出文件通过模板解析只有模板,没有集合
     * 每个sheet对应一个list,按照数量进行导出排序,key是sheet的NUM
     * @param params
     *            导出参数类
     * @param map
     *            模板集合
     * @return
     */</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token class-name">Workbook</span> <span class="token function">exportExcelClone</span><span class="token punctuation">(</span><span class="token class-name">Map</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Integer</span><span class="token punctuation">,</span> <span class="token class-name">List</span><span class="token punctuation">&lt;</span><span class="token class-name">Map</span><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span><span class="token punctuation">&gt;</span><span class="token punctuation">&gt;</span></span> map<span class="token punctuation">,</span>
                                       <span class="token class-name">TemplateExportParams</span> params<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">ExcelExportOfTemplateUtil</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">createExcelCloneByTemplate</span><span class="token punctuation">(</span>params<span class="token punctuation">,</span> map<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</pre><p>把自己需要导出很多份的数据组装到list里面统一个模板的map放到一个list,然后就是原始的模板sheetIndex,这样对比下来给你组装成你想要的,具体可以参考下demo</p>
<pre data-role="codeBlock" data-info="java" class="language-java"><span class="token annotation punctuation">@Test</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">cloneTest</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">throws</span> <span class="token class-name">Exception</span> <span class="token punctuation">{</span>
        <span class="token class-name">TemplateExportParams</span> params <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">TemplateExportParams</span><span class="token punctuation">(</span>
                <span class="token string">"doc/exportTemp.xls"</span><span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        params<span class="token punctuation">.</span><span class="token function">setHeadingRows</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        params<span class="token punctuation">.</span><span class="token function">setHeadingStartRow</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        params<span class="token punctuation">.</span><span class="token function">setStyle</span><span class="token punctuation">(</span><span class="token class-name">ExcelStyleType</span><span class="token punctuation">.</span>BORDER<span class="token punctuation">.</span><span class="token function">getClazz</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Map</span><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span><span class="token punctuation">&gt;</span></span> numOneList <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ArrayList</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> <span class="token number">10</span><span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token class-name">Map</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span></span> map <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">HashMap</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token comment">//sheet 1</span>
            map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"year"</span><span class="token punctuation">,</span> <span class="token string">"2013"</span> <span class="token operator">+</span> i<span class="token punctuation">)</span><span class="token punctuation">;</span>
            map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"sunCourses"</span><span class="token punctuation">,</span> list<span class="token punctuation">.</span><span class="token function">size</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token class-name">Map</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span></span> obj <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">HashMap</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"obj"</span><span class="token punctuation">,</span> obj<span class="token punctuation">)</span><span class="token punctuation">;</span>
            obj<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"name"</span><span class="token punctuation">,</span> list<span class="token punctuation">.</span><span class="token function">size</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token comment">// sheet 2</span>
            map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"month"</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token class-name">Map</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span></span> temp<span class="token punctuation">;</span>
            <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">int</span> j <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span> j <span class="token operator">&lt;</span> <span class="token number">8</span><span class="token punctuation">;</span> j<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                temp <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">HashMap</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                temp<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"per"</span><span class="token punctuation">,</span> j <span class="token operator">*</span> <span class="token number">10</span> <span class="token operator">+</span> <span class="token string">"---"</span> <span class="token operator">+</span> i<span class="token punctuation">)</span><span class="token punctuation">;</span>
                temp<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"mon"</span><span class="token punctuation">,</span> j <span class="token operator">*</span> <span class="token number">1000</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                temp<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"summon"</span><span class="token punctuation">,</span> j <span class="token operator">*</span> <span class="token number">10000</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"i"</span> <span class="token operator">+</span> j<span class="token punctuation">,</span> temp<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
            map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span>SHEET_NAME<span class="token punctuation">,</span> <span class="token string">"啊啊测试SHeet"</span> <span class="token operator">+</span> i<span class="token punctuation">)</span><span class="token punctuation">;</span>
            numOneList<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>map<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>


        <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Map</span><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span><span class="token punctuation">&gt;</span></span> numTowList <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ArrayList</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> <span class="token number">15</span><span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token class-name">Map</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span></span> oneMap <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">HashMap</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            oneMap<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"list"</span><span class="token punctuation">,</span> list<span class="token punctuation">)</span><span class="token punctuation">;</span>
            oneMap<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span>SHEET_NAME<span class="token punctuation">,</span> <span class="token string">"第二个测试SHeet"</span> <span class="token operator">+</span> i<span class="token punctuation">)</span><span class="token punctuation">;</span>
            numTowList<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>oneMap<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>

        <span class="token comment">// 把两个list 数据 put到对应的模板KEY 下面去</span>
        <span class="token class-name">Map</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Integer</span><span class="token punctuation">,</span> <span class="token class-name">List</span><span class="token punctuation">&lt;</span><span class="token class-name">Map</span><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span><span class="token punctuation">&gt;</span><span class="token punctuation">&gt;</span></span> realMap <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">HashMap</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        realMap<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> numOneList<span class="token punctuation">)</span><span class="token punctuation">;</span>
        realMap<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span> numTowList<span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token class-name">Workbook</span> book     <span class="token operator">=</span> <span class="token class-name">ExcelExportUtil</span><span class="token punctuation">.</span><span class="token function">exportExcelClone</span><span class="token punctuation">(</span>realMap<span class="token punctuation">,</span> params<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">File</span>     savefile <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">File</span><span class="token punctuation">(</span><span class="token string">"D:/excel/"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>savefile<span class="token punctuation">.</span><span class="token function">exists</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            savefile<span class="token punctuation">.</span><span class="token function">mkdirs</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token class-name">FileOutputStream</span> fos <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">FileOutputStream</span><span class="token punctuation">(</span><span class="token string">"D:/excel/exportCloneTemp.xls"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        book<span class="token punctuation">.</span><span class="token function">write</span><span class="token punctuation">(</span>fos<span class="token punctuation">)</span><span class="token punctuation">;</span>
        fos<span class="token punctuation">.</span><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token punctuation">}</span>
</pre><h2 class="mume-header" id="407" ebook-toc-level-2="" heading="3.6 &amp;#x6A21;&amp;#x677F;&amp;#x652F;&amp;#x6301;&amp;#x591A;&amp;#x5C42;&amp;#x5FAA;&amp;#x73AF; @Since 4.1.1">3.6 模板支持多层循环 @Since 4.1.1</h2>

<p>模板嵌套,写法和之前没有什么改变,可以判断字段是不是集合然后进行遍历,并对非集合字段自行单元格合并<br>
效果如下模板<br>
<img src="./easypoi_files/temploop.png" alt="模板导出效果" title="在这里输入图片标题"></p>
<p>输出效果<br>
<img src="./easypoi_files/temploop_result.png" alt="模板导出效果" title="在这里输入图片标题"></p>
<h1 class="mume-header" id="5" ebook-toc-level-1="" heading="4.Excel&amp;amp;Html&amp;#x4E92;&amp;#x8F6C;">4.Excel&amp;Html互转</h1>

<h2 class="mume-header" id="501" ebook-toc-level-2="" heading="4.1 Excel &amp;#x7684;Html&amp;#x9884;&amp;#x89C8;">4.1 Excel 的Html预览</h2>

<p>Excel预览，这里支持了比较简单的预览，样式也都可以转换过去，支持03 和 更高版本<br>
使用也是简单的很ExcelXorHtmlUtil.excelToHtml(params)，也支持图片的预览，demo如下</p>
<pre data-role="codeBlock" data-info="java" class="language-java">  <span class="token comment">/**
     * 07 版本EXCEL预览
     */</span>
    <span class="token annotation punctuation">@RequestMapping</span><span class="token punctuation">(</span><span class="token string">"07"</span><span class="token punctuation">)</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">toHtmlOf07Base</span><span class="token punctuation">(</span><span class="token class-name">HttpServletResponse</span> response<span class="token punctuation">)</span> <span class="token keyword">throws</span> <span class="token class-name">IOException</span><span class="token punctuation">,</span> <span class="token class-name">InvalidFormatException</span> <span class="token punctuation">{</span>
        <span class="token class-name">ExcelToHtmlParams</span> params <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ExcelToHtmlParams</span><span class="token punctuation">(</span><span class="token class-name">WorkbookFactory</span><span class="token punctuation">.</span><span class="token function">create</span><span class="token punctuation">(</span><span class="token class-name">POICacheManager</span><span class="token punctuation">.</span><span class="token function">getFile</span><span class="token punctuation">(</span><span class="token string">"exceltohtml/testExportTitleExcel.xlsx"</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        response<span class="token punctuation">.</span><span class="token function">getOutputStream</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">write</span><span class="token punctuation">(</span><span class="token class-name">ExcelXorHtmlUtil</span><span class="token punctuation">.</span><span class="token function">excelToHtml</span><span class="token punctuation">(</span>params<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getBytes</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token comment">/**
     * 03 版本EXCEL预览
     */</span>
    <span class="token annotation punctuation">@RequestMapping</span><span class="token punctuation">(</span><span class="token string">"03img"</span><span class="token punctuation">)</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">toHtmlOf03Img</span><span class="token punctuation">(</span><span class="token class-name">HttpServletResponse</span> response<span class="token punctuation">)</span> <span class="token keyword">throws</span> <span class="token class-name">IOException</span><span class="token punctuation">,</span> <span class="token class-name">InvalidFormatException</span> <span class="token punctuation">{</span>
        <span class="token class-name">ExcelToHtmlParams</span> params <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ExcelToHtmlParams</span><span class="token punctuation">(</span><span class="token class-name">WorkbookFactory</span><span class="token punctuation">.</span><span class="token function">create</span><span class="token punctuation">(</span><span class="token class-name">POICacheManager</span><span class="token punctuation">.</span><span class="token function">getFile</span><span class="token punctuation">(</span><span class="token string">"exceltohtml/exporttemp_img.xls"</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token boolean">true</span><span class="token punctuation">,</span><span class="token string">"yes"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        response<span class="token punctuation">.</span><span class="token function">getOutputStream</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">write</span><span class="token punctuation">(</span><span class="token class-name">ExcelXorHtmlUtil</span><span class="token punctuation">.</span><span class="token function">excelToHtml</span><span class="token punctuation">(</span>params<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getBytes</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</pre><p>返回一个string的html界面，输出到前台就可以了</p>
<h2 class="mume-header" id="502" ebook-toc-level-2="" heading="4.2 html&amp;#x8F6C;Excel&amp;#x66F4;&amp;#x795E;&amp;#x5947;&amp;#x7684;&amp;#x5BFC;&amp;#x51FA;">4.2 html转Excel更神奇的导出</h2>

<p>这个是一个MM提出的需求，需求原因是，她要导出一个比较复杂的Excel，无论用模板还是注解都比较难实现，所以她想到了这个方案，然后就实现了如下的方法，我的使用方法如下<br>
自己搞个html，然后用模板引擎，beetl，freemark等生成html，然后调用easypoi提供的方法转换成Excel，因为html的标签以及规则大家比Excel要熟悉的多，更容易编写复杂的table，然后easypoi转换成Excel再导出，麻烦了点，但是可以处理一些特定的情况，也同样生成两个版本的Excel都支持<br>
使用demo</p>
<pre data-role="codeBlock" data-info="java" class="language-java">    <span class="token annotation punctuation">@Test</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">htmlToExcelByStr</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">throws</span> <span class="token class-name">Exception</span> <span class="token punctuation">{</span>
        <span class="token class-name">StringBuilder</span> html <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">StringBuilder</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">Scanner</span> s <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Scanner</span><span class="token punctuation">(</span><span class="token function">getClass</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getResourceAsStream</span><span class="token punctuation">(</span><span class="token string">"/html/sample.html"</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token string">"utf-8"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">while</span> <span class="token punctuation">(</span>s<span class="token punctuation">.</span><span class="token function">hasNext</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            html<span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span>s<span class="token punctuation">.</span><span class="token function">nextLine</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        s<span class="token punctuation">.</span><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">Workbook</span> workbook <span class="token operator">=</span> <span class="token class-name">ExcelXorHtmlUtil</span><span class="token punctuation">.</span><span class="token function">htmlToExcel</span><span class="token punctuation">(</span>html<span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token class-name">ExcelType</span><span class="token punctuation">.</span>XSSF<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">File</span> savefile <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">File</span><span class="token punctuation">(</span><span class="token string">"D:\\home\\lemur"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>savefile<span class="token punctuation">.</span><span class="token function">exists</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            savefile<span class="token punctuation">.</span><span class="token function">mkdirs</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token class-name">FileOutputStream</span> fos <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">FileOutputStream</span><span class="token punctuation">(</span><span class="token string">"D:\\home\\lemur\\htmlToExcelByStr.xlsx"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        workbook<span class="token punctuation">.</span><span class="token function">write</span><span class="token punctuation">(</span>fos<span class="token punctuation">)</span><span class="token punctuation">;</span>
        fos<span class="token punctuation">.</span><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        workbook <span class="token operator">=</span> <span class="token class-name">ExcelXorHtmlUtil</span><span class="token punctuation">.</span><span class="token function">htmlToExcel</span><span class="token punctuation">(</span>html<span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token class-name">ExcelType</span><span class="token punctuation">.</span>HSSF<span class="token punctuation">)</span><span class="token punctuation">;</span>
        fos <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">FileOutputStream</span><span class="token punctuation">(</span><span class="token string">"D:\\home\\lemur\\htmlToExcelByStr.xls"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        workbook<span class="token punctuation">.</span><span class="token function">write</span><span class="token punctuation">(</span>fos<span class="token punctuation">)</span><span class="token punctuation">;</span>
        fos<span class="token punctuation">.</span><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token annotation punctuation">@Test</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">htmlToExcelByIs</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">throws</span> <span class="token class-name">Exception</span> <span class="token punctuation">{</span>
        <span class="token class-name">Workbook</span> workbook <span class="token operator">=</span> <span class="token class-name">ExcelXorHtmlUtil</span><span class="token punctuation">.</span><span class="token function">htmlToExcel</span><span class="token punctuation">(</span><span class="token function">getClass</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getResourceAsStream</span><span class="token punctuation">(</span><span class="token string">"/html/sample.html"</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token class-name">ExcelType</span><span class="token punctuation">.</span>XSSF<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">File</span> savefile <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">File</span><span class="token punctuation">(</span><span class="token string">"D:\\home\\lemur"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>savefile<span class="token punctuation">.</span><span class="token function">exists</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            savefile<span class="token punctuation">.</span><span class="token function">mkdirs</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token class-name">FileOutputStream</span> fos <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">FileOutputStream</span><span class="token punctuation">(</span><span class="token string">"D:\\home\\lemur\\htmlToExcelByIs.xlsx"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        workbook<span class="token punctuation">.</span><span class="token function">write</span><span class="token punctuation">(</span>fos<span class="token punctuation">)</span><span class="token punctuation">;</span>
        fos<span class="token punctuation">.</span><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        workbook <span class="token operator">=</span> <span class="token class-name">ExcelXorHtmlUtil</span><span class="token punctuation">.</span><span class="token function">htmlToExcel</span><span class="token punctuation">(</span><span class="token function">getClass</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getResourceAsStream</span><span class="token punctuation">(</span><span class="token string">"/html/sample.html"</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token class-name">ExcelType</span><span class="token punctuation">.</span>HSSF<span class="token punctuation">)</span><span class="token punctuation">;</span>
        fos <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">FileOutputStream</span><span class="token punctuation">(</span><span class="token string">"D:\\home\\lemur\\htmlToExcelByIs.xls"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        workbook<span class="token punctuation">.</span><span class="token function">write</span><span class="token punctuation">(</span>fos<span class="token punctuation">)</span><span class="token punctuation">;</span>
        fos<span class="token punctuation">.</span><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</pre><p>提供了流或者字符串的入参，内部都多了缓存，多次生成不会重复解析</p>
<h1 class="mume-header" id="6" ebook-toc-level-1="" heading="5.word&amp;#x6A21;&amp;#x677F;&amp;#x5904;&amp;#x7406;">5.word模板处理</h1>

<h2 class="mume-header" id="601" ebook-toc-level-2="" heading="5.1 word&amp;#x6A21;&amp;#x677F;&amp;#x5BFC;&amp;#x51FA;">5.1 word模板导出</h2>

<p>word模板和Excel模板用法基本一致，支持的标签也是一致的，仅仅支持07版本的word也是只能生成后缀是docx的文档，poi对doc支持不好，所以这里也就懒得支持了，支持表格和图片，具体demo如下</p>
<pre data-role="codeBlock" data-info="java" class="language-java"> <span class="token comment">/**

     * 简单导出包含图片

     */</span>
    <span class="token annotation punctuation">@Test</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">imageWordExport</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token class-name">Map</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span></span> map <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">HashMap</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"department"</span><span class="token punctuation">,</span> <span class="token string">"Easypoi"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"person"</span><span class="token punctuation">,</span> <span class="token string">"JueYue"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"time"</span><span class="token punctuation">,</span> format<span class="token punctuation">.</span><span class="token function">format</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">WordImageEntity</span> image <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">WordImageEntity</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        image<span class="token punctuation">.</span><span class="token function">setHeight</span><span class="token punctuation">(</span><span class="token number">200</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        image<span class="token punctuation">.</span><span class="token function">setWidth</span><span class="token punctuation">(</span><span class="token number">500</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        image<span class="token punctuation">.</span><span class="token function">setUrl</span><span class="token punctuation">(</span><span class="token string">"cn/afterturn/easypoi/test/word/img/testCode.png"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        image<span class="token punctuation">.</span><span class="token function">setType</span><span class="token punctuation">(</span><span class="token class-name">WordImageEntity</span><span class="token punctuation">.</span>URL<span class="token punctuation">)</span><span class="token punctuation">;</span>
        map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"testCode"</span><span class="token punctuation">,</span> image<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">try</span> <span class="token punctuation">{</span>
            <span class="token class-name">XWPFDocument</span> doc <span class="token operator">=</span> <span class="token class-name">WordExportUtil</span><span class="token punctuation">.</span><span class="token function">exportWord07</span><span class="token punctuation">(</span>
                <span class="token string">"cn/afterturn/easypoi/test/word/doc/Image.docx"</span><span class="token punctuation">,</span> map<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token class-name">FileOutputStream</span> fos <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">FileOutputStream</span><span class="token punctuation">(</span><span class="token string">"D:/excel/image.docx"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            doc<span class="token punctuation">.</span><span class="token function">write</span><span class="token punctuation">(</span>fos<span class="token punctuation">)</span><span class="token punctuation">;</span>
            fos<span class="token punctuation">.</span><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">Exception</span> e<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            e<span class="token punctuation">.</span><span class="token function">printStackTrace</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>

    <span class="token comment">/**

     * 简单导出没有图片和Excel

     */</span>
    <span class="token annotation punctuation">@Test</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token class-name">SimpleWordExport</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token class-name">Map</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span></span> map <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">HashMap</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"department"</span><span class="token punctuation">,</span> <span class="token string">"Easypoi"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"person"</span><span class="token punctuation">,</span> <span class="token string">"JueYue"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"time"</span><span class="token punctuation">,</span> format<span class="token punctuation">.</span><span class="token function">format</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"me"</span><span class="token punctuation">,</span><span class="token string">"JueYue"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"date"</span><span class="token punctuation">,</span> <span class="token string">"2015-01-03"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">try</span> <span class="token punctuation">{</span>
            <span class="token class-name">XWPFDocument</span> doc <span class="token operator">=</span> <span class="token class-name">WordExportUtil</span><span class="token punctuation">.</span><span class="token function">exportWord07</span><span class="token punctuation">(</span>
                <span class="token string">"cn/afterturn/easypoi/test/word/doc/Simple.docx"</span><span class="token punctuation">,</span> map<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token class-name">FileOutputStream</span> fos <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">FileOutputStream</span><span class="token punctuation">(</span><span class="token string">"D:/excel/simple.docx"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            doc<span class="token punctuation">.</span><span class="token function">write</span><span class="token punctuation">(</span>fos<span class="token punctuation">)</span><span class="token punctuation">;</span>
            fos<span class="token punctuation">.</span><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">Exception</span> e<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            e<span class="token punctuation">.</span><span class="token function">printStackTrace</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>

</pre><h2 class="mume-header" id="602" ebook-toc-level-2="" heading="5.2 &amp;#x5355;&amp;#x6A21;&amp;#x677F;&amp;#x751F;&amp;#x6210;&amp;#x591A;&amp;#x9875;&amp;#x6570;&amp;#x636E;">5.2 单模板生成多页数据</h2>

<p>应用场景,比如一个订单详情信息模板,但是有很多订单,需要导入到一个word里面</p>
<h1 class="mume-header" id="7" ebook-toc-level-1="" heading="6.PDF&amp;#x5904;&amp;#x7406;">6.PDF处理</h1>

<p>//TODO 为完成</p>
<h1 class="mume-header" id="8" ebook-toc-level-1="" heading="7. CSV&amp;#x5904;&amp;#x7406;">7. CSV处理</h1>

<h2 class="mume-header" id="801" ebook-toc-level-2="" heading="7.1 CSV&amp;#x5BFC;&amp;#x5165;&amp;#x5904;&amp;#x7406;">7.1 CSV导入处理</h2>

<p>导入提供两个方法,两个方法类似,都是基于注解或者Map,一个返回list,一个不返回list,数据量小用第一个,数据量大用第二个,推荐第二个,IReadHandler参考2.9方法是一一致的</p>
<pre data-role="codeBlock" data-info="java" class="language-java"><span class="token comment">/**
     * Csv 导入流适合大数据导入
     * 导入 数据源IO流,不返回校验结果 导入 字段类型 Integer,Long,Double,Date,String,Boolean
     *
     * @param inputstream
     * @param pojoClass
     * @param params
     * @return
     */</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">&gt;</span></span> <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">T</span><span class="token punctuation">&gt;</span></span> <span class="token function">importCsv</span><span class="token punctuation">(</span><span class="token class-name">InputStream</span> inputstream<span class="token punctuation">,</span> <span class="token class-name">Class</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span><span class="token punctuation">&gt;</span></span> pojoClass<span class="token punctuation">,</span>
                                        <span class="token class-name">CsvImportParams</span> params<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">CsvImportService</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">readExcel</span><span class="token punctuation">(</span>inputstream<span class="token punctuation">,</span> pojoClass<span class="token punctuation">,</span> params<span class="token punctuation">,</span> <span class="token keyword">null</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token comment">/**
     * Csv 导入流适合大数据导入
     * 导入 数据源IO流,不返回校验结果 导入 字段类型 Integer,Long,Double,Date,String,Boolean
     *
     * @param inputstream
     * @param pojoClass
     * @param params
     * @return
     */</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">importCsv</span><span class="token punctuation">(</span><span class="token class-name">InputStream</span> inputstream<span class="token punctuation">,</span> <span class="token class-name">Class</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span><span class="token punctuation">&gt;</span></span> pojoClass<span class="token punctuation">,</span>
                                        <span class="token class-name">CsvImportParams</span> params<span class="token punctuation">,</span> <span class="token class-name">IReadHandler</span> readHandler<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">new</span> <span class="token class-name">CsvImportService</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">readExcel</span><span class="token punctuation">(</span>inputstream<span class="token punctuation">,</span> pojoClass<span class="token punctuation">,</span> params<span class="token punctuation">,</span> readHandler<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</pre><p>CsvImportParams 的参数描述如下</p>
<table>
<thead>
<tr>
<th>属性</th>
<th>类型</th>
<th>默认值</th>
<th>功能</th>
</tr>
</thead>
<tbody>
<tr>
<td>encoding</td>
<td>String</td>
<td>UTF8</td>
<td>文件编码</td>
</tr>
<tr>
<td>spiltMark</td>
<td>String</td>
<td>,</td>
<td>分隔符</td>
</tr>
<tr>
<td>textMark</td>
<td>String</td>
<td>"</td>
<td>字符串识别,可以去掉,需要前后一致</td>
</tr>
<tr>
<td>titleRows</td>
<td>int</td>
<td>0</td>
<td>表格头,忽略</td>
</tr>
<tr>
<td>headRows</td>
<td>int</td>
<td>1</td>
<td>标题</td>
</tr>
<tr>
<td>startRows</td>
<td>int</td>
<td>0</td>
<td>标题起忽略行数</td>
</tr>
<tr>
<td>verifyGroup</td>
<td>Class[]</td>
<td>null</td>
<td>校验,参考java validation</td>
</tr>
<tr>
<td>needVerify</td>
<td>boolean</td>
<td>false</td>
<td>是否需要校验,默认false</td>
</tr>
<tr>
<td>verifyHandler</td>
<td>IExcelVerifyHandler</td>
<td>null</td>
<td>自定义校验接口</td>
</tr>
<tr>
<td>lastOfInvalidRow</td>
<td>int</td>
<td>0</td>
<td>最后跳过行</td>
</tr>
<tr>
<td>keyIndex</td>
<td>int</td>
<td>null</td>
<td>重要字段,判断是否需要读取</td>
</tr>
</tbody>
</table>
<p>demo如下,CsvImportParams.GBK需要指定文件编码,这个希望大家注意</p>
<pre data-role="codeBlock" data-info="java" class="language-java">    <span class="token annotation punctuation">@Test</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">test</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">try</span> <span class="token punctuation">{</span>
            <span class="token class-name">Date</span> start <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            LOGGER<span class="token punctuation">.</span><span class="token function">debug</span><span class="token punctuation">(</span><span class="token string">"start"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token class-name">CsvImportParams</span> params <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">CsvImportParams</span><span class="token punctuation">(</span><span class="token class-name">CsvImportParams</span><span class="token punctuation">.</span>GBK<span class="token punctuation">)</span><span class="token punctuation">;</span>
            params<span class="token punctuation">.</span><span class="token function">setTitleRows</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token class-name">CsvImportUtil</span><span class="token punctuation">.</span><span class="token function">importCsv</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">FileInputStream</span><span class="token punctuation">(</span>
                            <span class="token keyword">new</span> <span class="token class-name">File</span><span class="token punctuation">(</span><span class="token class-name">FileUtilTest</span><span class="token punctuation">.</span><span class="token function">getWebRootPath</span><span class="token punctuation">(</span><span class="token string">"csv/BigDataExport.csv"</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                    <span class="token class-name">MsgClient</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">,</span> params<span class="token punctuation">,</span> <span class="token keyword">new</span> <span class="token class-name">IReadHandler</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                        <span class="token annotation punctuation">@Override</span>
                        <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">handler</span><span class="token punctuation">(</span><span class="token class-name">Object</span> o<span class="token punctuation">)</span> <span class="token punctuation">{</span>

                        <span class="token punctuation">}</span>

                        <span class="token annotation punctuation">@Override</span>
                        <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">doAfterAll</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>

                        <span class="token punctuation">}</span>
                    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            LOGGER<span class="token punctuation">.</span><span class="token function">debug</span><span class="token punctuation">(</span><span class="token string">"end,time is {}"</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getTime</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">-</span> start<span class="token punctuation">.</span><span class="token function">getTime</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token operator">/</span> <span class="token number">1000</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">Exception</span> e<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
</pre><h2 class="mume-header" id="802" ebook-toc-level-2="" heading="7.2 CSV&amp;#x5BFC;&amp;#x51FA;">7.2 CSV导出</h2>

<p>csv的导出基本上和excel的导出一致,大体参数也是一致的<br>
CsvExportParams 的参数描述如下</p>
<table>
<thead>
<tr>
<th>属性</th>
<th>类型</th>
<th>默认值</th>
<th>功能</th>
</tr>
</thead>
<tbody>
<tr>
<td>encoding</td>
<td>String</td>
<td>UTF8</td>
<td>文件编码</td>
</tr>
<tr>
<td>spiltMark</td>
<td>String</td>
<td>,</td>
<td>分隔符</td>
</tr>
<tr>
<td>textMark</td>
<td>String</td>
<td>"</td>
<td>字符串识别,可以去掉,需要前后一致</td>
</tr>
<tr>
<td>titleRows</td>
<td>int</td>
<td>0</td>
<td>表格头,忽略</td>
</tr>
<tr>
<td>headRows</td>
<td>int</td>
<td>1</td>
<td>标题</td>
</tr>
<tr>
<td>exclusions</td>
<td>String[]</td>
<td>0</td>
<td>忽略的字段</td>
</tr>
<tr>
<td>isCreateHeadRows</td>
<td>boolean</td>
<td>true</td>
<td>创建表头</td>
</tr>
</tbody>
</table>
<p>使用起来也十分简单,基本和excel保持了一直方式,一个是对象导出,一个是自由导出参考##2.6自由的导出,不同的是没有返回对象,需要自己把流传入,我给你直接写入,从速度和效率上来讲,速度远超excel</p>
<pre data-role="codeBlock" data-info="java" class="language-java"><span class="token comment">/**
     * @param params    表格标题属性
     * @param pojoClass Excel对象Class
     * @param dataSet   Excel对象数据List
     */</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">exportCsv</span><span class="token punctuation">(</span><span class="token class-name">CsvExportParams</span> params<span class="token punctuation">,</span> <span class="token class-name">Class</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span><span class="token punctuation">&gt;</span></span> pojoClass<span class="token punctuation">,</span>
                                 <span class="token class-name">Collection</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span><span class="token punctuation">&gt;</span></span> dataSet<span class="token punctuation">,</span> <span class="token class-name">OutputStream</span> outputStream<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">new</span> <span class="token class-name">CsvExportService</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">createCsv</span><span class="token punctuation">(</span>outputStream<span class="token punctuation">,</span> params<span class="token punctuation">,</span> pojoClass<span class="token punctuation">,</span> dataSet<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token comment">/**
     * 根据Map创建对应的Excel
     *
     * @param params     表格标题属性
     * @param entityList Map对象列表
     * @param dataSet    Excel对象数据List
     */</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">exportCsv</span><span class="token punctuation">(</span><span class="token class-name">CsvExportParams</span> params<span class="token punctuation">,</span> <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">ExcelExportEntity</span><span class="token punctuation">&gt;</span></span> entityList<span class="token punctuation">,</span>
                                 <span class="token class-name">Collection</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token operator">?</span><span class="token punctuation">&gt;</span></span> dataSet<span class="token punctuation">,</span> <span class="token class-name">OutputStream</span> outputStream<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">new</span> <span class="token class-name">CsvExportService</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">createCsvOfList</span><span class="token punctuation">(</span>outputStream<span class="token punctuation">,</span> params<span class="token punctuation">,</span> entityList<span class="token punctuation">,</span> dataSet<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</pre><p>一个简单的小demo</p>
<pre data-role="codeBlock" data-info="java" class="language-java">  <span class="token annotation punctuation">@Test</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">exportCsv</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">throws</span> <span class="token class-name">IOException</span> <span class="token punctuation">{</span>
        <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">MsgClient</span><span class="token punctuation">&gt;</span></span> list <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ArrayList</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">MsgClient</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">Date</span> start <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">CsvExportParams</span> params <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">CsvExportParams</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> <span class="token number">500000</span><span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token class-name">MsgClient</span> client <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">MsgClient</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            client<span class="token punctuation">.</span><span class="token function">setBirthday</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            client<span class="token punctuation">.</span><span class="token function">setClientName</span><span class="token punctuation">(</span><span class="token string">"小明"</span> <span class="token operator">+</span> i<span class="token punctuation">)</span><span class="token punctuation">;</span>
            client<span class="token punctuation">.</span><span class="token function">setClientPhone</span><span class="token punctuation">(</span><span class="token string">"18797"</span> <span class="token operator">+</span> i<span class="token punctuation">)</span><span class="token punctuation">;</span>
            client<span class="token punctuation">.</span><span class="token function">setCreateBy</span><span class="token punctuation">(</span><span class="token string">"JueYue"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            client<span class="token punctuation">.</span><span class="token function">setId</span><span class="token punctuation">(</span><span class="token string">"1"</span> <span class="token operator">+</span> i<span class="token punctuation">)</span><span class="token punctuation">;</span>
            client<span class="token punctuation">.</span><span class="token function">setRemark</span><span class="token punctuation">(</span><span class="token string">"测试"</span> <span class="token operator">+</span> i<span class="token punctuation">)</span><span class="token punctuation">;</span>
            list<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>client<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>

        <span class="token class-name">File</span> savefile <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">File</span><span class="token punctuation">(</span><span class="token string">"D:/excel/"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>savefile<span class="token punctuation">.</span><span class="token function">exists</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            savefile<span class="token punctuation">.</span><span class="token function">mkdirs</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token class-name">FileOutputStream</span> fos <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">FileOutputStream</span><span class="token punctuation">(</span><span class="token string">"D:/excel/ExcelExportBigData.bigDataExport.csv"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">CsvExportUtil</span><span class="token punctuation">.</span><span class="token function">exportCsv</span><span class="token punctuation">(</span>params<span class="token punctuation">,</span> <span class="token class-name">MsgClient</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">,</span> list<span class="token punctuation">,</span> fos<span class="token punctuation">)</span><span class="token punctuation">;</span>
        fos<span class="token punctuation">.</span><span class="token function">flush</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        fos<span class="token punctuation">.</span><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"导出完成"</span> <span class="token operator">+</span> <span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getTime</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">-</span> start<span class="token punctuation">.</span><span class="token function">getTime</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</pre><h1 class="mume-header" id="9" ebook-toc-level-1="" heading="8.Spring MVC">8.Spring MVC</h1>

<h1 class="mume-header" id="10" ebook-toc-level-1="" heading="8.1 View &amp;#x4ECB;&amp;#x7ECD;">8.1 View 介绍</h1>

<p>easypoi view 项目是为了更简单的方便搭建在导出时候的操作，利用spring mvc 的view 封装，更加符合spring mvc的风格<br>
view下面包括多个 view的实现</p>
<ul>
<li>EasypoiBigExcelExportView 大数据量导出</li>
<li>EasypoiMapExcelView    map 列表导出</li>
<li>EasypoiPDFTemplateView pdf导出</li>
<li>EasypoiSingleExcelView 注解导出</li>
<li>EasypoiTemplateExcelView 模板导出</li>
<li>EasypoiTemplateWordView word模板导出</li>
<li>MapGraphExcelView 图表导出</li>
</ul>
<p>view的是使用方法大同小异，都有一个对应的bean，里面保护指定的参数常量<br>
同意用modelmap.put(‘常量参数名’，‘值’)就可以，最后返回这个view名字</p>
<p>注解目录扫描的时候加上<br>
<strong>cn.afterturn.easypoi.view</strong><br>
就可以使用了</p>
<h2 class="mume-header" id="1001" ebook-toc-level-2="" heading="8.2  &amp;#x5927;&amp;#x6570;&amp;#x636E;&amp;#x5BFC;&amp;#x51FA;View&amp;#x7684;&amp;#x7528;&amp;#x6CD5;">8.2  大数据导出View的用法</h2>

<p><strong>EasypoiBigExcelExportView <strong>是针对大数据量导出特定的View,在跳转到这个View的时候不需要查询数据,而且这个View自己去查询数据,用户只要实现</strong>IExcelExportServer</strong>接口就可以了<br>
对应的常量类<strong>BigExcelConstants</strong></p>
<pre data-role="codeBlock" data-info="java" class="language-java"><span class="token keyword">public</span> <span class="token keyword">interface</span> <span class="token class-name">IExcelExportServer</span> <span class="token punctuation">{</span>
    <span class="token comment">/**
     * 查询数据接口
     * @param obj    查询条件
     * @param page   当前页数
     * @return
     */</span>
    <span class="token keyword">public</span> <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Object</span><span class="token punctuation">&gt;</span></span> <span class="token function">selectListForExcelExport</span><span class="token punctuation">(</span><span class="token class-name">Object</span> obj<span class="token punctuation">,</span> <span class="token keyword">int</span> page<span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token punctuation">}</span>
</pre><p>EasypoiBigExcelExportView  判断是否还有下一页的条件是,如果selectListForExcelExport 返回null就认为是最后一页了,如果返回有数据这page+1继续查询<br>
在我们自己的controller中</p>
<pre data-role="codeBlock" data-info="java" class="language-java"> <span class="token annotation punctuation">@RequestMapping</span><span class="token punctuation">(</span><span class="token string">"load"</span><span class="token punctuation">)</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">downloadByPoiBaseView</span><span class="token punctuation">(</span><span class="token class-name">ModelMap</span> map<span class="token punctuation">,</span> <span class="token class-name">HttpServletRequest</span> request<span class="token punctuation">,</span>
                                      <span class="token class-name">HttpServletResponse</span> response<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token class-name">ExportParams</span> params <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ExportParams</span><span class="token punctuation">(</span><span class="token string">"2412312"</span><span class="token punctuation">,</span> <span class="token string">"测试"</span><span class="token punctuation">,</span> <span class="token class-name">ExcelType</span><span class="token punctuation">.</span>XSSF<span class="token punctuation">)</span><span class="token punctuation">;</span>
        params<span class="token punctuation">.</span><span class="token function">setFreezeCol</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token class-name">BigExcelConstants</span><span class="token punctuation">.</span>CLASS<span class="token punctuation">,</span> <span class="token class-name">MsgClient</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token class-name">BigExcelConstants</span><span class="token punctuation">.</span>PARAMS<span class="token punctuation">,</span> params<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">//就是我们的查询参数,会带到接口中,供接口查询使用</span>
        map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token class-name">BigExcelConstants</span><span class="token punctuation">.</span>DATA_PARAMS<span class="token punctuation">,</span> <span class="token keyword">new</span> <span class="token class-name">HashMap</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span><span class="token class-name">String</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token class-name">BigExcelConstants</span><span class="token punctuation">.</span>DATA_INTER<span class="token punctuation">,</span>excelExportServer<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">PoiBaseView</span><span class="token punctuation">.</span><span class="token function">render</span><span class="token punctuation">(</span>map<span class="token punctuation">,</span> request<span class="token punctuation">,</span> response<span class="token punctuation">,</span> <span class="token class-name">BigExcelConstants</span><span class="token punctuation">.</span>EASYPOI_BIG_EXCEL_VIEW<span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token punctuation">}</span>
</pre><p>我们需要把参数条件封装成map或者其他类型,上面的obj可以把参数自己转回来 参数名字 <strong>BigExcelConstants.DATA_PARAM</strong><br>
然后把实现查询的接口注入进来就可以了<br>
<em><strong>map.put(BigExcelConstants.DATA_INTER,excelExportServer);</strong></em><br>
后面就和其他View一样了</p>
<h2 class="mume-header" id="1002" ebook-toc-level-2="" heading="8.3 &amp;#x6CE8;&amp;#x89E3;&amp;#x5BFC;&amp;#x51FA;View&amp;#x7528;&amp;#x6CD5;">8.3 注解导出View用法</h2>

<p>注解导出的View是这个<strong>EasypoiSingleExcelView</strong>,其实View大家可以忽略不看，主要用到的还是他对应的bean对象<br>
<em><strong>NormalExcelConstants</strong></em> 注解到处还比较简单，大家只要把datalist，class和params 这几个参数put下就可以了。<br>
具体的案例</p>
<pre data-role="codeBlock" data-info="java" class="language-java"> <span class="token annotation punctuation">@RequestMapping</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token keyword">public</span> <span class="token class-name">String</span> <span class="token function">download</span><span class="token punctuation">(</span><span class="token class-name">ModelMap</span> map<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">MsgClient</span><span class="token punctuation">&gt;</span></span> list <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ArrayList</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">MsgClient</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> <span class="token number">100</span><span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token class-name">MsgClient</span> client <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">MsgClient</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            client<span class="token punctuation">.</span><span class="token function">setBirthday</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            client<span class="token punctuation">.</span><span class="token function">setClientName</span><span class="token punctuation">(</span><span class="token string">"小明"</span> <span class="token operator">+</span> i<span class="token punctuation">)</span><span class="token punctuation">;</span>
            client<span class="token punctuation">.</span><span class="token function">setClientPhone</span><span class="token punctuation">(</span><span class="token string">"18797"</span> <span class="token operator">+</span> i<span class="token punctuation">)</span><span class="token punctuation">;</span>
            client<span class="token punctuation">.</span><span class="token function">setCreateBy</span><span class="token punctuation">(</span><span class="token string">"JueYue"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            client<span class="token punctuation">.</span><span class="token function">setId</span><span class="token punctuation">(</span><span class="token string">"1"</span> <span class="token operator">+</span> i<span class="token punctuation">)</span><span class="token punctuation">;</span>
            client<span class="token punctuation">.</span><span class="token function">setRemark</span><span class="token punctuation">(</span><span class="token string">"测试"</span> <span class="token operator">+</span> i<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token class-name">MsgClientGroup</span> group <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">MsgClientGroup</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            group<span class="token punctuation">.</span><span class="token function">setGroupName</span><span class="token punctuation">(</span><span class="token string">"测试"</span> <span class="token operator">+</span> i<span class="token punctuation">)</span><span class="token punctuation">;</span>
            client<span class="token punctuation">.</span><span class="token function">setGroup</span><span class="token punctuation">(</span>group<span class="token punctuation">)</span><span class="token punctuation">;</span>
            list<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>client<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token class-name">ExportParams</span> params <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ExportParams</span><span class="token punctuation">(</span><span class="token string">"2412312"</span><span class="token punctuation">,</span> <span class="token string">"测试"</span><span class="token punctuation">,</span> <span class="token class-name">ExcelType</span><span class="token punctuation">.</span>XSSF<span class="token punctuation">)</span><span class="token punctuation">;</span>
        params<span class="token punctuation">.</span><span class="token function">setFreezeCol</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token class-name">NormalExcelConstants</span><span class="token punctuation">.</span>DATA_LIST<span class="token punctuation">,</span> list<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 数据集合</span>
        map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token class-name">NormalExcelConstants</span><span class="token punctuation">.</span>CLASS<span class="token punctuation">,</span> <span class="token class-name">MsgClient</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//导出实体</span>
        map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token class-name">NormalExcelConstants</span><span class="token punctuation">.</span>PARAMS<span class="token punctuation">,</span> params<span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//参数</span>
        map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token class-name">NormalExcelConstants</span><span class="token punctuation">.</span>FILE_NAME<span class="token punctuation">,</span> params<span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//文件名称</span>
        <span class="token keyword">return</span> <span class="token class-name">NormalExcelConstants</span><span class="token punctuation">.</span>EASYPOI_EXCEL_VIEW<span class="token punctuation">;</span><span class="token comment">//View名称</span>

    <span class="token punctuation">}</span>
</pre><p>和非View导出基本一致，只是把调用方法封装了而已，其他参数还都是一样的，具体可以看下测试项目的<br>
<a href="https://gitee.com/lemur/easypoi-test/blob/master/src/main/java/cn/afterturn/easypoi/view/EasypoiSingleExcelViewTest.java">EasypoiSingleExcelViewTest</a></p>
<h2 class="mume-header" id="1003" ebook-toc-level-2="" heading="8.4 &amp;#x6CE8;&amp;#x89E3;&amp;#x53D8;&amp;#x79CD;Map&amp;#x7C7B;&amp;#x578B;&amp;#x7684;&amp;#x5BFC;&amp;#x51FA;View">8.4 注解变种Map类型的导出View</h2>

<p>作为动态注解存在的 List<excelexportentity> ，也提供的单独的View方便大家使用，**EasypoiMapExcelView **<br>
使用方法都是一样，直接看下例子吧</excelexportentity></p>
<pre data-role="codeBlock" data-info="java" class="language-java"> <span class="token annotation punctuation">@RequestMapping</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token keyword">public</span> <span class="token class-name">String</span> <span class="token function">download</span><span class="token punctuation">(</span><span class="token class-name">ModelMap</span> modelMap<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">ExcelExportEntity</span><span class="token punctuation">&gt;</span></span> entity <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ArrayList</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">ExcelExportEntity</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">ExcelExportEntity</span> excelentity <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ExcelExportEntity</span><span class="token punctuation">(</span><span class="token string">"姓名"</span><span class="token punctuation">,</span> <span class="token string">"name"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        excelentity<span class="token punctuation">.</span><span class="token function">setNeedMerge</span><span class="token punctuation">(</span><span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        entity<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>excelentity<span class="token punctuation">)</span><span class="token punctuation">;</span>
        entity<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">ExcelExportEntity</span><span class="token punctuation">(</span><span class="token string">"性别"</span><span class="token punctuation">,</span> <span class="token string">"sex"</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        excelentity <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ExcelExportEntity</span><span class="token punctuation">(</span><span class="token keyword">null</span><span class="token punctuation">,</span> <span class="token string">"students"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">ExcelExportEntity</span><span class="token punctuation">&gt;</span></span> temp <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ArrayList</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">ExcelExportEntity</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        temp<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">ExcelExportEntity</span><span class="token punctuation">(</span><span class="token string">"姓名"</span><span class="token punctuation">,</span> <span class="token string">"name"</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        temp<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">ExcelExportEntity</span><span class="token punctuation">(</span><span class="token string">"性别"</span><span class="token punctuation">,</span> <span class="token string">"sex"</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        excelentity<span class="token punctuation">.</span><span class="token function">setList</span><span class="token punctuation">(</span>temp<span class="token punctuation">)</span><span class="token punctuation">;</span>
        entity<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>excelentity<span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Map</span><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span><span class="token punctuation">&gt;</span></span> list <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ArrayList</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Map</span><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">Map</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span></span> map<span class="token punctuation">;</span>
        <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> <span class="token number">10</span><span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            map <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">HashMap</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"name"</span><span class="token punctuation">,</span> <span class="token string">"1"</span> <span class="token operator">+</span> i<span class="token punctuation">)</span><span class="token punctuation">;</span>
            map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"sex"</span><span class="token punctuation">,</span> <span class="token string">"2"</span> <span class="token operator">+</span> i<span class="token punctuation">)</span><span class="token punctuation">;</span>

            <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Map</span><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span><span class="token punctuation">&gt;</span></span> tempList <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ArrayList</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Map</span><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            tempList<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>map<span class="token punctuation">)</span><span class="token punctuation">;</span>
            tempList<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>map<span class="token punctuation">)</span><span class="token punctuation">;</span>
            map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"students"</span><span class="token punctuation">,</span> tempList<span class="token punctuation">)</span><span class="token punctuation">;</span>

            list<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>map<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>

        <span class="token class-name">ExportParams</span> params <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ExportParams</span><span class="token punctuation">(</span><span class="token string">"2412312"</span><span class="token punctuation">,</span> <span class="token string">"测试"</span><span class="token punctuation">,</span> <span class="token class-name">ExcelType</span><span class="token punctuation">.</span>XSSF<span class="token punctuation">)</span><span class="token punctuation">;</span>
        params<span class="token punctuation">.</span><span class="token function">setFreezeCol</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        modelMap<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token class-name">MapExcelConstants</span><span class="token punctuation">.</span>MAP_LIST<span class="token punctuation">,</span> list<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//数据集合</span>
        modelMap<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token class-name">MapExcelConstants</span><span class="token punctuation">.</span>ENTITY_LIST<span class="token punctuation">,</span> entity<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//注解集合</span>
        modelMap<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token class-name">MapExcelConstants</span><span class="token punctuation">.</span>PARAMS<span class="token punctuation">,</span> params<span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//参数</span>
        modelMap<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token class-name">MapExcelConstants</span><span class="token punctuation">.</span>FILE_NAME<span class="token punctuation">,</span> <span class="token string">"EasypoiMapExcelViewTest"</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//文件名称</span>
        <span class="token keyword">return</span> <span class="token class-name">MapExcelConstants</span><span class="token punctuation">.</span>EASYPOI_MAP_EXCEL_VIEW<span class="token punctuation">;</span><span class="token comment">//View名称</span>

    <span class="token punctuation">}</span>
</pre><p>具体案例参考<a href="https://gitee.com/lemur/easypoi-test/blob/master/src/main/java/cn/afterturn/easypoi/view/EasypoiMapExcelViewTest.java">EasypoiMapExcelViewTest</a></p>
<h2 class="mume-header" id="1004" ebook-toc-level-2="" heading="8.5Excel&amp;#x6A21;&amp;#x677F;&amp;#x5BFC;&amp;#x51FA;View">8.5Excel模板导出View</h2>

<p>模板导出提供的EasypoiTemplateExcelView以及对应的bean <strong><em>TemplateExcelConstants</em></strong><br>
案例</p>
<pre data-role="codeBlock" data-info="java" class="language-java"><span class="token annotation punctuation">@RequestMapping</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token keyword">public</span> <span class="token class-name">String</span> <span class="token function">download</span><span class="token punctuation">(</span><span class="token class-name">ModelMap</span> modelMap<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token class-name">Map</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span></span> map <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">HashMap</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">TemplateExportParams</span> params <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">TemplateExportParams</span><span class="token punctuation">(</span>
            <span class="token string">"doc/foreach.xlsx"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">TemplateExcelExportEntity</span><span class="token punctuation">&gt;</span></span> list <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ArrayList</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">TemplateExcelExportEntity</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> <span class="token number">4</span><span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token class-name">TemplateExcelExportEntity</span> entity <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">TemplateExcelExportEntity</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            entity<span class="token punctuation">.</span><span class="token function">setIndex</span><span class="token punctuation">(</span>i <span class="token operator">+</span> <span class="token number">1</span> <span class="token operator">+</span> <span class="token string">""</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            entity<span class="token punctuation">.</span><span class="token function">setAccountType</span><span class="token punctuation">(</span><span class="token string">"开源项目"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            entity<span class="token punctuation">.</span><span class="token function">setProjectName</span><span class="token punctuation">(</span><span class="token string">"EasyPoi "</span> <span class="token operator">+</span> i <span class="token operator">+</span> <span class="token string">"期"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            entity<span class="token punctuation">.</span><span class="token function">setAmountApplied</span><span class="token punctuation">(</span>i <span class="token operator">*</span> <span class="token number">10000</span> <span class="token operator">+</span> <span class="token string">""</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            entity<span class="token punctuation">.</span><span class="token function">setApprovedAmount</span><span class="token punctuation">(</span><span class="token punctuation">(</span>i <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token operator">*</span> <span class="token number">10000</span> <span class="token operator">-</span> <span class="token number">100</span> <span class="token operator">+</span> <span class="token string">""</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            list<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>entity<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"entitylist"</span><span class="token punctuation">,</span> list<span class="token punctuation">)</span><span class="token punctuation">;</span>
        map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"manmark"</span><span class="token punctuation">,</span> <span class="token string">"1"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"letest"</span><span class="token punctuation">,</span> <span class="token string">"12345678"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"fntest"</span><span class="token punctuation">,</span> <span class="token string">"12345678.2341234"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"fdtest"</span><span class="token punctuation">,</span> <span class="token keyword">null</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Map</span><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span><span class="token punctuation">&gt;</span></span> mapList <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ArrayList</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Map</span><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> <span class="token number">1</span><span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token class-name">Map</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span></span> testMap <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">HashMap</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

            testMap<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"id"</span><span class="token punctuation">,</span> <span class="token string">"xman"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            testMap<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"name"</span><span class="token punctuation">,</span> <span class="token string">"小明"</span> <span class="token operator">+</span> i<span class="token punctuation">)</span><span class="token punctuation">;</span>
            testMap<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"sex"</span><span class="token punctuation">,</span> <span class="token string">"1"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            mapList<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>testMap<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"maplist"</span><span class="token punctuation">,</span> mapList<span class="token punctuation">)</span><span class="token punctuation">;</span>

        mapList <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ArrayList</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Map</span><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> <span class="token number">6</span><span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token class-name">Map</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span></span> testMap <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">HashMap</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

            testMap<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"si"</span><span class="token punctuation">,</span> <span class="token string">"xman"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            mapList<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>testMap<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"sitest"</span><span class="token punctuation">,</span> mapList<span class="token punctuation">)</span><span class="token punctuation">;</span>
        modelMap<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token class-name">TemplateExcelConstants</span><span class="token punctuation">.</span>FILE_NAME<span class="token punctuation">,</span> <span class="token string">"用户信息"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//文件名</span>
        modelMap<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token class-name">TemplateExcelConstants</span><span class="token punctuation">.</span>PARAMS<span class="token punctuation">,</span> params<span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//参数</span>
        modelMap<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token class-name">TemplateExcelConstants</span><span class="token punctuation">.</span>MAP_DATA<span class="token punctuation">,</span> map<span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//数据</span>
        <span class="token keyword">return</span> <span class="token class-name">TemplateExcelConstants</span><span class="token punctuation">.</span>EASYPOI_TEMPLATE_EXCEL_VIEW<span class="token punctuation">;</span><span class="token comment">//view名称</span>

    <span class="token punctuation">}</span>
</pre><p>具体案例<a href="https://gitee.com/lemur/easypoi-test/blob/master/src/main/java/cn/afterturn/easypoi/view/EasypoiTemplateExcelViewTest.java">EasypoiTemplateExcelViewTest</a></p>
<h2 class="mume-header" id="1005" ebook-toc-level-2="" heading="8.6 PoiBaseView.render view&amp;#x7684;&amp;#x8865;&amp;#x6551;">8.6 PoiBaseView.render view的补救</h2>

<p>假如因为不可抗拒或者其他神奇的原因，view导出无法使用，作者遇到过好几次了，各种神奇原因都有，提供一个统一的封装，算是一个补救措施吧<br>
上面的modelMap写法和设置参数还是一样，最后直接输出就可以了<br>
PoiBaseView.render(modelMap, request, response,View名称);</p>
<p>看个简单demo</p>
<pre data-role="codeBlock" data-info="java" class="language-java"> <span class="token annotation punctuation">@RequestMapping</span><span class="token punctuation">(</span><span class="token string">"load"</span><span class="token punctuation">)</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">downloadByPoiBaseView</span><span class="token punctuation">(</span><span class="token class-name">ModelMap</span> map<span class="token punctuation">,</span> <span class="token class-name">HttpServletRequest</span> request<span class="token punctuation">,</span>
                                      <span class="token class-name">HttpServletResponse</span> response<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">MsgClient</span><span class="token punctuation">&gt;</span></span> list <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ArrayList</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">MsgClient</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> <span class="token number">100</span><span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token class-name">MsgClient</span> client <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">MsgClient</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            client<span class="token punctuation">.</span><span class="token function">setBirthday</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            client<span class="token punctuation">.</span><span class="token function">setClientName</span><span class="token punctuation">(</span><span class="token string">"小明"</span> <span class="token operator">+</span> i<span class="token punctuation">)</span><span class="token punctuation">;</span>
            client<span class="token punctuation">.</span><span class="token function">setClientPhone</span><span class="token punctuation">(</span><span class="token string">"18797"</span> <span class="token operator">+</span> i<span class="token punctuation">)</span><span class="token punctuation">;</span>
            client<span class="token punctuation">.</span><span class="token function">setCreateBy</span><span class="token punctuation">(</span><span class="token string">"JueYue"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            client<span class="token punctuation">.</span><span class="token function">setId</span><span class="token punctuation">(</span><span class="token string">"1"</span> <span class="token operator">+</span> i<span class="token punctuation">)</span><span class="token punctuation">;</span>
            client<span class="token punctuation">.</span><span class="token function">setRemark</span><span class="token punctuation">(</span><span class="token string">"测试"</span> <span class="token operator">+</span> i<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token class-name">MsgClientGroup</span> group <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">MsgClientGroup</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            group<span class="token punctuation">.</span><span class="token function">setGroupName</span><span class="token punctuation">(</span><span class="token string">"测试"</span> <span class="token operator">+</span> i<span class="token punctuation">)</span><span class="token punctuation">;</span>
            client<span class="token punctuation">.</span><span class="token function">setGroup</span><span class="token punctuation">(</span>group<span class="token punctuation">)</span><span class="token punctuation">;</span>
            list<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>client<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token class-name">ExportParams</span> params <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ExportParams</span><span class="token punctuation">(</span><span class="token string">"2412312"</span><span class="token punctuation">,</span> <span class="token string">"测试"</span><span class="token punctuation">,</span> <span class="token class-name">ExcelType</span><span class="token punctuation">.</span>XSSF<span class="token punctuation">)</span><span class="token punctuation">;</span>
        params<span class="token punctuation">.</span><span class="token function">setFreezeCol</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token class-name">NormalExcelConstants</span><span class="token punctuation">.</span>DATA_LIST<span class="token punctuation">,</span> list<span class="token punctuation">)</span><span class="token punctuation">;</span>
        map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token class-name">NormalExcelConstants</span><span class="token punctuation">.</span>CLASS<span class="token punctuation">,</span> <span class="token class-name">MsgClient</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token class-name">NormalExcelConstants</span><span class="token punctuation">.</span>PARAMS<span class="token punctuation">,</span> params<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">PoiBaseView</span><span class="token punctuation">.</span><span class="token function">render</span><span class="token punctuation">(</span>map<span class="token punctuation">,</span> request<span class="token punctuation">,</span> response<span class="token punctuation">,</span> <span class="token class-name">NormalExcelConstants</span><span class="token punctuation">.</span>EASYPOI_EXCEL_VIEW<span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token punctuation">}</span>
</pre><h1 class="mume-header" id="11" ebook-toc-level-1="" heading="9.spring boot">9.spring boot</h1>

<h1 class="mume-header" id="12" ebook-toc-level-1="" heading="9.1 spring boot start">9.1 spring boot start</h1>

<p>随着spring boot的越来越流行,不可免俗的我们也推出了easypoi-spring-boot-starter,方便大家的引用和依赖</p>
<pre data-role="codeBlock" data-info="xml" class="language-xml"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">&gt;</span></span>cn.afterturn<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">&gt;</span></span>easypoi-spring-boot-starter<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>version</span><span class="token punctuation">&gt;</span></span>4.0.0<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>version</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">&gt;</span></span>
</pre><p>加入其他不需要改动就可以完美的玩耍了,如果你不需要web服务,那只要依赖easypoi-base就可以了</p>
<h1 class="mume-header" id="13" ebook-toc-level-1="" heading="10.&amp;#x5E38;&amp;#x89C1;&amp;#x95EE;&amp;#x9898;&amp;#x89E3;&amp;#x7B54;">10.常见问题解答</h1>

<h3 class="mume-header" id="1301" ebook-toc-level-3="" heading="10.1 &amp;#x5BFC;&amp;#x5165;&amp;#x65F6;&amp;#x4E3A;&amp;#x5565;&amp;#x8FD9;&amp;#x884C;&amp;#x4E3A;&amp;#x7A7A;&amp;#x8FD8;&amp;#x8BFB;&amp;#x53D6; &amp;#x6216;&amp;#x8005;&amp;#x4E3A;&amp;#x5565;&amp;#x53EA;&amp;#x6709;3&amp;#x884C;&amp;#x5374;&amp;#x8BFB;&amp;#x53D6;&amp;#x4E86;100&amp;#x884C;&amp;#x6570;&amp;#x636E;">10.1 导入时为啥这行为空还读取 或者为啥只有3行却读取了100行数据</h3>

<p>在导入参数ImportParams 有一个属性keyIndex</p>
<pre data-role="codeBlock" data-info="java" class="language-java">    <span class="token comment">/**
     * 主键设置,如何这个cell没有值,就跳过 或者认为这个是list的下面的值
     * 大家不理解，去掉这个
     */</span>

    <span class="token keyword">private</span> <span class="token class-name">Integer</span>             keyIndex         <span class="token operator">=</span> <span class="token keyword">null</span><span class="token punctuation">;</span>
</pre><p>最早是默认为0的,但是很多说有问题,就取消默认值了,如果你遇到上面的问题,请不他改为你肯定不为空的一列比如0,就可以解决上面问题了</p>
<h3 class="mume-header" id="1690101" ebook-toc-level-3="" heading="10.2 &amp;#x6A21;&amp;#x677F;&amp;#x5982;&amp;#x4F55;&amp;#x5408;&amp;#x5E76;&amp;#x5355;&amp;#x5143;&amp;#x683C;">10.2 模板如何合并单元格</h3>

<p>提供了PoiMergeCellUtil类供大家生成wb之后,自己再调用</p>
<pre data-role="codeBlock" data-info="java" class="language-java"><span class="token comment">/**
     * 纵向合并相同内容的单元格
     *
     * @param sheet
     * @param startRow 开始行
     * @param columns  需要处理的列
     */</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">mergeCells</span><span class="token punctuation">(</span><span class="token class-name">Sheet</span> sheet<span class="token punctuation">,</span> <span class="token keyword">int</span> startRow<span class="token punctuation">,</span> <span class="token class-name">Integer</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> columns<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>columns <span class="token operator">==</span> <span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">ExcelExportException</span><span class="token punctuation">(</span><span class="token string">"至少需要处理1列"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token class-name">Map</span><span class="token operator">&lt;</span><span class="token class-name">Integer</span><span class="token punctuation">,</span> <span class="token keyword">int</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token operator">&gt;</span> mergeMap <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">HashMap</span><span class="token operator">&lt;</span><span class="token class-name">Integer</span><span class="token punctuation">,</span> <span class="token keyword">int</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token operator">&gt;</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> columns<span class="token punctuation">.</span>length<span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            mergeMap<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span>columns<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token keyword">null</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token function">mergeCells</span><span class="token punctuation">(</span>sheet<span class="token punctuation">,</span> mergeMap<span class="token punctuation">,</span> startRow<span class="token punctuation">,</span> sheet<span class="token punctuation">.</span><span class="token function">getLastRowNum</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</pre><p>这个逻辑是,只要一列连续值是相同的就合并</p>
<h3 class="mume-header" id="1690102" ebook-toc-level-3="" heading="10.3 &amp;#x5982;&amp;#x4F55;&amp;#x8BA9;&amp;#x5355;&amp;#x5143;&amp;#x683C;&amp;#x662F;&amp;#x6570;&amp;#x7EC4;">10.3 如何让单元格是数组</h3>

<p>参考2.7样式自定义,让你这个单元格是数组类型的样式就可以了</p>
<p>如果是模板 n:</p>
<h3 class="mume-header" id="1690103" ebook-toc-level-3="" heading="10.4 &amp;#x7C7B;&amp;#x627E;&amp;#x4E0D;&amp;#x5230;&amp;#x600E;&amp;#x4E48;&amp;#x529E;">10.4 类找不到怎么办</h3>

<p><a href="https://www.findjar.com/index.x">https://www.findjar.com/index.x</a></p>
<h3 class="mume-header" id="1690104" ebook-toc-level-3="" heading="10.5 replace NULL&amp;#x503C;&amp;#x95EE;&amp;#x9898;">10.5 replace NULL值问题</h3>

<p>@excel replace = { "客户银行卡_OA01", "客户金账户_OA02", "客户存管账户_OA03","渠道金账户_OA04", "营销款账户_OA05"}<br>
private String outAccountType<br>
当outAccountType 值为null的时候,excel会转为 null字符串</p>
<p>可以这么配置**"_null"**,就可以解决上述问题</p>
<pre data-role="codeBlock" data-info="java" class="language-java"><span class="token annotation punctuation">@Excel</span><span class="token punctuation">(</span>name <span class="token operator">=</span> <span class="token string">"出账账户类型"</span><span class="token punctuation">,</span> width <span class="token operator">=</span> <span class="token number">20</span><span class="token punctuation">,</span> replace <span class="token operator">=</span> <span class="token punctuation">{</span> <span class="token string">"客户银行卡_OA01"</span><span class="token punctuation">,</span> <span class="token string">"客户金账户_OA02"</span><span class="token punctuation">,</span> <span class="token string">"客户存管账户_OA03"</span>
            <span class="token punctuation">,</span><span class="token string">"渠道金账户_OA04"</span><span class="token punctuation">,</span> <span class="token string">"营销款账户_OA05"</span><span class="token punctuation">,</span> <span class="token string">"_null"</span><span class="token punctuation">}</span><span class="token punctuation">,</span> orderNum <span class="token operator">=</span> <span class="token string">"6"</span><span class="token punctuation">)</span>
</pre><h3 class="mume-header" id="1690105" ebook-toc-level-3="" heading="10.6 &amp;#x65E0;&amp;#x8868;&amp;#x5934;&amp;#x6216;&amp;#x8005;&amp;#x8868;&amp;#x5934;&amp;#x91CD;&amp;#x590D;&amp;#x4E0D;&amp;#x597D;&amp;#x5224;&amp;#x65AD;&amp;#x5982;&amp;#x4F55;&amp;#x89E3;&amp;#x51B3;">10.6 无表头或者表头重复不好判断如何解决</h3>

<p>fixedIndex 字段可以直接让你固定列跳过那些判断直接读取数据</p>
<pre data-role="codeBlock" data-info="java" class="language-java"><span class="token keyword">if</span> <span class="token punctuation">(</span>excelEntity<span class="token punctuation">.</span><span class="token function">getFixedIndex</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">!=</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            temp<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"FIXED_"</span> <span class="token operator">+</span> excelEntity<span class="token punctuation">.</span><span class="token function">getFixedIndex</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> excelEntity<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
            temp<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span>excelEntity<span class="token punctuation">.</span><span class="token function">getName</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> excelEntity<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</pre><p>你可以在@Excel上使用,也可以在自己ExcelImportEntity是写</p>
<h3 class="mume-header" id="1690106" ebook-toc-level-3="" heading="10.7 &amp;#x6A21;&amp;#x677F;&amp;#x5BFC;&amp;#x51FA;&amp;#x4E00;&amp;#x5BF9;&amp;#x591A;&amp;#xFF0C;&amp;#x5982;&amp;#x4F55;&amp;#x5408;&amp;#x5E76;&amp;#x5355;&amp;#x5143;&amp;#x683C;&amp;#x548C;&amp;#x5FAA;&amp;#x73AF;">10.7 模板导出一对多，如何合并单元格和循环</h3>

</div>
    </div>
  

</article>
            </div>
        </div>
    <script src="./easypoi_files/jquery-1.10.2.min.js.下载"></script>
    <script src="./easypoi_files/jquery.ztree.all-3.5.min.js.下载"></script>
    <script src="./easypoi_files/jquery.ztree_toc.min.js.下载"></script>
	<script src="./easypoi_files/include.js.下载"></script>
    <script type="text/javascript">
        $(document).ready(function(){
			$(".markdown-body").load("easypoidoc.html",function(){
				$('#tree').ztree_toc({
                is_auto_number:false,
                documment_selector:'.markdown-body',
                is_expand_all: true
            });
			$('#readme').height($('.markdown-preview div').height() + 500);
			setTimeout(function(){
				$('#readme').height($('.markdown-preview div').height() + 500);
			},2000)
			});
			$("#cnzz_stat_icon_1264442706").hide();

        });
    </script>
    <script type="text/javascript">var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");document.write(unescape("%3Cspan id='cnzz_stat_icon_1264442706'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s19.cnzz.com/z_stat.php%3Fid%3D1264442706%26show%3Dpic' type='text/javascript'%3E%3C/script%3E"));</script><span id="cnzz_stat_icon_1264442706" style="display: none;"><a href="https://www.cnzz.com/stat/website.php?web_id=1264442706" target="_blank" title="站长统计"><img border="0" hspace="0" vspace="0" src="./easypoi_files/pic.gif"></a></span><script src="./easypoi_files/z_stat.php" type="text/javascript"></script><script src="./easypoi_files/core.php" charset="utf-8" type="text/javascript"></script>

	<footer class="footer" style="width: 70%; margin-left: 25%;">
	 <p>© <script>document.write(new Date().getFullYear());</script>2020鲁ICP备15023514号<a href="https://opensource.afterturn.cn/" target="_blank">Lemur, Inc.</a> Licensed under <a href="http://opensource.org/licenses/MIT" target="_blank">MIT license</a>. by the Lemur Team.</p>
		</footer>
    
</body></html>